Bonito Bonito - 12 days ago 5
PHP Question

Loop into an array of array with PHP

I have this array:

$bookings[] = array(
'booking_id' => '1',
'client_name' => 'John',
'client_firstname' => 'Peter',
'days' => array(
array(
'day_id' => '2016-11-23',
'room_id' => '2'
),
array(
'day_id' => '2016-11-24',
'room_id' => '2'
),
array(
'day_id' => '2016-11-25',
'room_id' => '4'
)
)
)


I'm looking loop into the
days
array with PHP.

How is it possible please ?

Thanks for your help.

Answer

demo

 <?php
    $bookings[] = array(
        'booking_id' => '1', 
        'client_name' => 'John', 
        'client_firstname' => 'Peter', 
        'days' => array(
            array(
                'day_id' => '2016-11-23',
                'room_id' => '2'
            ),
            array(
                'day_id' => '2016-11-24',
                'room_id' => '2'
            ),
            array(
                'day_id' => '2016-11-25',
                'room_id' => '4'
            )
        )
    );
    foreach($bookings as $booking)
    {
      foreach($booking['days'] as $day)
      {
        echo $day['day_id'];
        echo "\n";
      }
    }
Comments