Loop and Insert PHP multi-dimensional array into mysql

Viewed 735

I have a multi-dimensional array in php that look like this :

 Array
    (
    [0] => Array
    (
        [day] => 0
        [periods] => Array
            (
                [0] => Array
                    (
                        [0] => 01:00
                        [1] => 01:30
                    )

                [1] => Array
                    (
                        [0] => 02:30
                        [1] => 03:00
                    )

            )

    )

[1] => Array
    (
        [day] => 1
        [periods] => Array
            (
                [0] => Array
                    (
                        [0] => 01:30
                        [1] => 02:00
                    )

            )

    )

The "day" key reffer to the day so day[0] = "monday" And the "periods" key reffer to the hour that the user has selected on the same day.

So in the day[0] there is a 'periods' array that reffer to anthor array that store the hour , start 01:00, end 01:30 start 02:30, end 03:00

I try to foreach loop this array but I can not find a way. I want to enter this value for each hour to mysql like so:

    $sql  = "INSERT INTO task_list (
            task, day, hour
            ) VALUES (?, ?, ?)
    ";  

ex : day: 0 start 1:00 , day: 0 end 1:30

any suggestions?

1 Answers
Related