Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8956655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:50:08+00:00 2026-06-15T14:50:08+00:00

My foreach loop isn’t displaying the values that match the keys they belong to

  • 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);
             }
         }

      }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:50:10+00:00Added an answer on June 15, 2026 at 2:50 pm

    you have to print

    $value
    

    and not

    $key['name']
    

    because as you state:

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

    then logically

     $key["name"] 
    

    doesnt exist.

    $key, in this case is either ‘name’ or ‘profile_image_url’. It’s a srting, not an array.

    You need to do this:

    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);
    
    
    
                                     }
                            }
    
                   }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this foreach statement that is supposed to cycle through an array, but
This foreach loop works fine while testing and only returning 5 rows of data,
I am using a foreach loop within PHP similar to this: foreach ($class->getAttributes() as
I have a foreach loop in jQuery going through each 'div.panel', I need to
I'm running a foreach loop for the whole script that checks 9 things. Let's
I have a foreach loop that needs converting to a for or while loop.
I'm trying to loop through a QHash using foreach and get each pair in
This isn't that complicated of a question, but I can't wrap my head around
I know that the foreach loop used in the following example doesn't compile. But
I got a foreach-loop, but want to show one echo next to one specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.