-2

I have this array in PHP:

 [data] => Array
        (
            [BOO_item_quantity] => Array
                (
                    [0] => 1
                    [1] => 6
                )

            [BOO_item_id] => Array
                (
                    [0] => 18
                    [1] => 13
                )

            [BOO_item_price] => Array
                (
                    [0] => 3
                    [1] => 0
                )

        )

How is it possible to loop into this to get something like this please ?

Quantity = 1 - Item_Id = 18 - Price = 3
Quantity = 6 - Item_Id = 13 - Price = 0

Thanks.

F__M
  • 1,518
  • 1
  • 19
  • 34

1 Answers1

0

You can use a foreach statement to loop over the elements the first sub-array:

$data = array(
    'BOO_item_quantity' => array(1,6),
    'BOO_item_id' => array(18,13),
    'BOO_item_price' =>array(3,0)
);
foreach($data['BOO_item_quantity'] as $index=>$value) {
    print 'Quantity = '.$value.' - Item_Id = '.$data['BOO_item_id'][$index].' - Price = '.$data['BOO_item_price'][$index].'<br />';
}

See it in action at phpfiddle.

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58