使用PHP循环到数组数组

时间:2016-11-22 01:57:17

标签: php arrays

我有这个数组,

$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'
        )
    )
)

我正在寻找使用PHP循环到days数组。

请问怎么可能?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

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";
      }
    }