数组拼接多维数组

时间:2015-02-12 22:35:15

标签: arrays multidimensional-array splice

如何选择' $ reference_cart_id'来自此session_cart_array的变量,以便我可以查询db以查找属于该客户的其他匹配ID?当我循环回到未定义的错误时,会出现reference_id& reference_cart_id

cartOutput --Array
 (
 [0] => Array
    (
        [item_id] => 133
        [quantity] => 1
        [size] => MED
        [color] => Black
        [username] => medallion9
        [reference_cart_id] => DU3ZWRjNTkwNGYy
        [reference_id] => 6cefe27
    )

[1] => Array
    (
        [item_id] => 134
        [quantity] => 1
        [size] => LG
        [color] => Camel-501
        [username] => medallion9
        [reference_cart_id] => DU3ZWRjNTkwNGYy
        [reference_id] => 6cefe27
    )
 )

1 个答案:

答案 0 :(得分:0)

您可以使用array_maphttp://php.net/manual/en/function.array-map.php):

$idArray = array_map(function($a){ return $a['reference_cart_id']; },$cartArray);