Home > Article > Backend Development > PHP一个二维数组的有关问题
PHP一个二维数组的问题
我有一个二维数组,想通过一个元素goods_id的值得到对应的其他元素的值
数组如下,知道goods_id = 123,如何得到goods_name,goods_price。。。。
最简单的方法是?
$goods = array(
0 => array('goods_id' => 123, //goods_id
'goods_name' => 测试商品, //商品名称
'goods_price' => '12.10', //商品价格
'max_number' => '5', //限购数量
'thumb_url' => 'http://.....' //缩略图
),
1 => array('goods_id' => 124,
'goods_name' => 测试商品2,
'goods_price' => '12.10',
'max_number' => '',
'thumb_url' => 'http://.....'
),
2 => array('goods_id' => 125,
'goods_name' => 测试商品3,
'goods_price' => '12.10',
'max_number' => '',
'thumb_url' => 'http://.....'
)
);
$goods = array(<br> 123 => array('goods_id' => 123, //goods_id<br> 'goods_name' => 测试商品, //商品名称<br> 'goods_price' => '12.10', //商品价格<br> 'max_number' => '5', //限购数量 <div class="clear"> </div>