tags:

views:

52

answers:

2

I have an array that I can't seem to get my data back out of. What I would like is for each name (test1...) to have multiple urls associated with them. If you look at the last test (test5), there are 2 urls but this foreach loop only gives me one. Why?

Here is the array structure and my foreach loop.

Array
(
    [test1] => Array
        (
            [0] => http://www....
        )

    [test2] => Array
        (
            [0] => http://www....
        )

    [test3] => Array
        (
            [0] => http://www....
        )

    [test4] => Array
        (
            [0] => http://www....
        )

    [test5] => Array
        (
            [0] => http://www.yahoo.com
            [1] => http://www.google.com
        )

)


foreach($source as $name=>$url)
{
    foreach($url as $_url);
    {
      echo $name.' - ';
      echo $_url.'<br>';
    }
}
+2  A: 

You have a semicolon after your second foreach: foreach(...); {... which shouldn't be there. The code below works as you would expect.

<?php
  $source = array(
    'test5' => array(
      "http://www.yahoo.com",
      "http://www.google.com"
    )
  );

  foreach ($source as $name => $url) {
    foreach($url as $_url) {
      echo $name.' - ';
      echo $_url.'<br>';
    }
  }
Ben Marini
OMG.. I can't believe I missed that. :) Thanks!
John
A: 
iangraham