-2

I get the data from a checkout form, when user have two or more product, I have this array.

Array(
[nome] => Array
    (
        [0] => Nature herbs
        [1] => Nature Baby
    )

[qty] => Array
    (
        [0] => 1
        [1] => 2
    )

[prezzo] => Array
    (
        [0] =>     $23.00
        [1] =>     $34.00
    )
)

But, how can I change it into something like this.

Array(
[0] => Array
    (
        [nome] => Nature herbs
        [qty] => 1
        [prezzo] => $23.00
    )

[1] => Array
    (
       [nome] =>  Nature Baby
       [qty] => 2
       [prezzo] => $34.00

    )
)

Thanks!

Charlie Fish
  • 13,172
  • 14
  • 64
  • 137
  • 5
    Possible duplicate of [How can I sort arrays and data in PHP?](http://stackoverflow.com/questions/17364127/how-can-i-sort-arrays-and-data-in-php) – Machavity Jul 31 '16 at 17:55
  • Stack Overflow is not a free code writing service, please show your code/effort and what the actual problem is. – Rizier123 Jul 31 '16 at 18:29

1 Answers1

0

You could simply loop through the "nome" array and write all the data into a second array, using the same index.

$array2 = array();

for ($i = 0; $i < count($array1['nome']); $i++) {
    $array2[$i]['nome'] = $array1['nome'][$i];
    $array2[$i]['qty'] = $array1['qty'][$i];
    $array2[$i]['prezzo'] = $array1['prezzo'][$i];
}
cklamm
  • 71
  • 4