2010-12-14 120 views
1

我怎麼能做出一個很好的搜索結果,如谷歌 我不能包圍我的頭這麼多。謝謝你提供的所有幫助。多維數組上的foreach循環

Array 
(
    [summary] => Array 
     (
      [what] => pizza 
      [where] => city 
     ) 

    [listings] => Array 
     (
      [0] => Array 
       (
        [parent] => 
        [contents] => Array 
         (
          [Video] => Array 
           (
            [avail] => 
           ) 
         ) 

        [id] => 1114638 
        [name] => Sexy house 
        [address] => Array 
         (
          [street] => 3 King St E 
          [city] => loversLane 
          [prov] => AB 
          [pcode] => L8N1A1 
         ) 

        [geoCoded] => Array 
         (
          [latitude] => 43.256373 
          [longitude] => -79.868167 
         ) 

       ) 

     ) 

) 

this works good at printing: 

     function recursivePrint($elem) { 
    foreach ($elem as $key => $value) { 
     if (is_array($value)) 
     $this->recursivePrint($value); 
     else 
     print $value.'<br>'; 
    } 
} 

但我希望能夠鏈接到結果等等有地理編碼作爲變量,所以我可以使用地圖。儘可能多地控制線條。

+0

Thaks雅各代碼段沒有想和我一起工作。 – mrpowless 2010-12-14 17:35:05

回答

0

你選擇包圓各一個的HTML是你的,但是這應該使它明顯瞭如何在PHP中使用數組:

echo 'Results for '.$elem['summary']['what'].' '.$elem['summary']['where'].'<br />'; 

foreach($elem['listings'] as $listing) 
{ 
echo $listing['name'].'<br />'; 
echo $listing['address']['street'].'<br />'; 
echo $listing['address']['city'].'<br />'; 
echo '<a href="http://maps.google.com/maps?hl=en&tab=wl&q='.$listing['geoCoded']['latitude'].','.$listing['geoCoded']['longitude'].'" title="View location on a map">'.$listing['address']['pcode'].'</a>'; 
echo '<br /><br />'; 
} 
+0

謝謝!你教會了我我永遠不會忘記的事情! – mrpowless 2010-12-14 18:06:28