0

I have a $date array like this:

[1]=> array(11) {
    ["meetingname"]=> string(33) "win2008connectcurrent0423131"
    [0]=> array(3) {
        ["scoid"]=> string(7) "3557012"
        ["datecreated"]=> string(19) "2013-05-23 10:02:39"
        ["numparticipants"]=> string(1) "3"
    }
    [1]=> array(3) {
        ["scoid"]=> string(7) "3557012"
        ["datecreated"]=> string(19) "2013-05-23 14:40:06"
        ["numparticipants"]=> string(1) "3"
    }
}   

foreach($date[0] as $key =>  $meetings){
    print "$key = $meetings\n";////yields scoid = 3557012
}

And, as you can see above, I am looping over individual elements. The first element (not indexed) is always meetingname; the rest of the elements are indexed and themselves contain arrays with three elements in each array--in the above code they are [0] and [1].

What I need to do is make the $meetings as an array containing [0] and then [1] etc, depending on the number of elements. So essentially, the output for print should be an array (I can also use var_dump) with key/values of [0] but right not it only outputs individual keys and their values, for example, as you can see above, scoid=3557012. I will need, something all keys/values in the $meetings variable, something like:

{
    ["scoid"]=> string(7) "3557012"
    ["datecreated"]=> string(19) "2013-05-23 10:02:39"
    ["numparticipants"]=> string(1) "3"
}

How can I fix the foreach loop for that?

2
  • Why don't you include the arrays you want inside your question? print_r is okey, but still everybody will be wasting time converting it into a real array. Commented Jun 5, 2013 at 13:46
  • I think I have the desired array as code block at the nearly very end of my Question--that's how the $meetings should look like. Commented Jun 5, 2013 at 13:50

2 Answers 2

4

please Try this. hope it help.

foreach($date as $key =>  $meetings){
       if($key == "meetingname")
         continue;
       else
         print "$meetings\n";
 }
0
1

You can just create a new array and add the meetings to that one

<?php
$meetings = array();
foreach($date[1] as $key=>$meeting) {
  if (!is_int($key))
    continue;  //only handle numeric keys, incase you ever change the name of the first key 'meetingname'

  $meetings[] = $meeting
}

var_dump($meetings);
?>
1
  • Hi, $date[1] is not an element--it must be $date[0]. Anyway, @Hasina's answer is working. Thanks for your help! Commented Jun 5, 2013 at 14:01

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.