0

My foreach loop isn't displaying the values that match the keys they belong to .. I'm looping through this foreach loop to retrieve the names and images of my twitter followers and it's not displaying the values , I'm pretty sure the key names are correct .. Because when I just use the $value variable , it will echo both the name and image links are the same time but I want to catch the image link , put it in the img src html format to display the images .. Below is my code.

 for ($i=0; $i <= count($array); $i++) {
     if (is_array($array[$i])) {
         foreach($array[$i] as $key => $value) {
             if ($key =='name' || $key =='profile_image_url') { 
                 echo "<b>". $key["name"]."</b><br />";
                 echo "<img src='".$key['profile_image_url']."' width='100' height='100'/>";
             } else {
                 unset($key);
             }
         }

      }
 }
4

2 に答える 2

1

印刷する必要があります

$value

ではない

$key['name']

あなたが述べているように:

if($key =='name' || $key =='profile_image_url') 

次に論理的に

 $key["name"] 

存在しません。

$key、この場合は「name」または「profile_image_url」です。配列ではなくストリングです。

これを行う必要があります:

for ($i=0; $i <= count($array); $i++)
                      {



                       if(is_array($array[$i]))
                      {
                         foreach($array[$i] as $key => $value) {

                        if ($key =='name' || $key =='profile_image_url') 
                               { 
                                 echo "<b>". $value."</b><br />";
                              //echo "<img src='".$key['profile_image_url']."' width='100' height='100'/>";


                                   }
                         else {



                              unset($key);



                                 }
                        }

               }
        }
于 2012-12-09T07:37:09.007 に答える
0

あなたが使う

$key["name"]

アイテムを表示します。そうではない$valueでしょうか?

于 2012-12-09T07:37:45.663 に答える