PHP:如何索引多个嵌套数组的列表?

时间:2012-06-13 18:05:55

标签: php multidimensional-array arraylist

如何索引下面的数组,

array
(
    [1403847357564066] => Array
        (
            [quantity_request] => 1
            [time_created] => 1339603485
            [variant] => Array
                (
                )
        )

    [1403873546800880] => Array
        (
            [quantity_request] => 1
            [time_created] => 1339602425
            [variant] => Array
                (
                )

        )

)

或者我可以得到,

array(
[0] => array(
      [1403847357564066] => Array
                (
                    [quantity_request] => 1
                    [time_created] => 1339609120
                    [variant] => Array
                        (
                        )

                )
       ),
[1] => array(

            [1403847343435137] => Array
                (
                    [quantity_request] => 1
                    [time_created] => 1339609500
                    [variant] => Array
                        (
                        )

                )
        )

1 个答案:

答案 0 :(得分:2)

$newarray=array();
foreach ($oldarray as $k=>$v) $newarray[]=array($k=>$v);