1

Quick Question:

I have the following array (multidimensional):

    Array ( 
        [preorder] => 0 
        [data] => Array ( 
             [0] => 03:00:00 
             [1] => 03:15:00 
             [2] => 03:30:00 
             [3] => 03:45:00 
             [4] => 04:00:00 
             [5] => 04:15:00 
             [6] => 04:30:00 
             [7] => 04:45:00 
             [8] => 05:00:00 
             ) 
      ) 

How, if possible do I use a foreach to get the options from the [data] subarray. So forexample if I were to write in PHP:

foreach($arrayname as $key=>$data) {
    echo $data[$i];
    $i++;
}

But this doesn't seem to work. I know how to do this if each item in the array is set as say 'time_slot' or something, but I'm not entirely sure how this could work?

Any insight would be greatly appreciated.

0

1 Answer 1

6

As $arrayname['data'] is an array you can apply foreach function to it:

foreach($arrayname['data'] as $key=>$data) {
    echo "Key = " . $key ." and value = " . $data . "<br>\n";
}
Sign up to request clarification or add additional context in comments.

2 Comments

Right on, before you were iterating through the containing array when you really wanted was to be iterating through the sub-array.
Thanks so much. I can't believe I couldn't work that out. Working through til 5:30am clearly isn't great for the mental abilities! haha

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.