0

In PHP, is there any built-in array function that I could use to change an array...

From:

Array (
    [0] => Array
        (
            [item_id] => 1
        )

    [1] => Array
        (
            [item_id] => 3
        )

    [2] => Array
        (
            [item_id] => 2
        )

)

To:

Array
(
     [item_id] => Array ( [0] => 1, [1] => 2, [2] => 3 )
)

Thanks for your help.

user3583721
  • 327
  • 2
  • 4
  • 14

1 Answers1

3

Even if you cant find a built-in function, you can write a small loop. Although im sure this can also be done with array_map

foreach($yourArray as $subArray)
{
 $newArray["item_id"][]=$subArray["item_id"];
}
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95