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 8057427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:01:40+00:00 2026-06-05T09:01:40+00:00

print_r($samplearr) prints the following for my array containing 3 items: Array ( [4722] =>

  • 0

print_r($samplearr) prints the following for my array containing 3 items:

Array ( [4722] => Array ( [value1] => 52 [value2] => 46 )
Array ( [4922] => Array ( [value1] => 22 [value2] => 47 )
Array ( [7522] => Array ( [value1] => 47 [value2] => 85 )

I want to put these into an HTML table so I was doing a foreach but its not doing what I expected:

foreach($samplearr as $item){
     print "<tr><td>" . key($item) . "</td><td>" . $samplearr['value1'] . "</td><td>" . $samplearr['value2'] . "</td></tr>";
}

Which is returning:

<tr><td>value1</td><td>52</td><td>46</td></tr>

This would be the first output I am wanting:

<tr><td>4722</td><td>52</td><td>46</td></tr>

What function do I need to be using instead of key($item) to get the 4722?

  • 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-05T09:01:42+00:00Added an answer on June 5, 2026 at 9:01 am

    Try this:

    foreach($samplearr as $key => $item){
      print "<tr><td>" 
          . $key 
          . "</td><td>"  
          . $item['value1'] 
          . "</td><td>" 
          . $item['value2'] 
          . "</td></tr>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code: print_r($_GET); echo '<br />'; echo isset($_GET['logout'])?'yes':'no'; prints: Array ( [logoout] =>
<?php print_r($response->response->docs); ?> Outputs the following: Array ( [0] => Object ( [_fields:private] =>
print_r($tokens); $tokens = array_unique($tokens); print_r($tokens); Gives the following output: Array ( [0] => Array
I want to print an array the way that print_r is printing it without
When I print_r($_COOKIE); , I get following result. Array ( [filters] => Array (
Using print_r returns the following array: Array ( [5358] => red [1] => green
I have the following array called $order (as printed out by print_r): stdClass Object
I have the following data from print_r($_SESSION) : Array ( [totalprice] => 954 [cart]
print_r($array) results I retrieved some values from database and got the following result while
I get this array when I print_r($_POST) , from the below result I want

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.