Jump to content

Recommended Posts

Hello, I have a multi-dim array, $a which produces the following var_export($a):

array (
  'some_ID' => 5,
  'Create_Date' => '2004-02-20 15:18:13',
  'some_Name' => 'foo',
  'some_Description' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.',
  'Priority' => 1,
  'some_URL' => 'http://www.fooname.com',
  'Featured' => 1,
  'Admin_ID' => 30,
  'Status' => 'A',
  'Last_Update' => '2004-08-31 11:29:27',
)

array (
  'some_ID' => 16,
  'Create_Date' => '2000-06-14 10:10:36',
  'some_Name' => 'bar',
  'some_Description' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.',
  'Priority' => 2,
  'some_URL' => 'http://www.bardomain.com',
  'Featured' => 0,
  'Admin_ID' => NULL,
  'Status' => 'A',
  'Last_Update' => '2003-08-18 15:43:22',
)

array (
  'some_ID' => 19,
  'Create_Date' => '2006-06-19 11:15:59',
  'some_Name' => '555',
  'some_Description' => '555',
  'Priority' => 555,
  'some_URL' => '555',
  'Featured' => 0,
  'Admin_ID' => NULL,
  'Status' => 'A',
  'Last_Update' => '2006-10-17 10:28:32',
)

array (
  'some_ID' => 20,
  'Create_Date' => '2006-06-20 11:36:01',
  'some_Name' => 'anotherfoo',
  'some_Description' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.',
  'Priority' => 7,
  'some_URL' => 'http://www.anotherfoo.com/',
  'Featured' => 0,
  'Admin_ID' => NULL,
  'Status' => 'A',
  'Last_Update' => '2005-02-18 15:43:22',
)

My question is:  How do I iterate through and only extract the value of 'some_ID' and place that into a table?
Link to comment
https://forums.phpfreaks.com/topic/24334-multi-dimensional-arrays/
Share on other sites

Try something like this for your table...

[code]
<?php
// Open the table
echo "<table width=\"300\" cellspacing=\"0\" cellpadding=\"3\" border=\"1\">";

// Loop through each instance in the array
foreach ($a as $key => $value){
  echo "<tr><td width=\"300\" align=\"center\">{$a[$key]['some_ID']}</td></tr>\n"; // Echo the table rows
}

// Close off the table
echo "</table>\n";
?>
[/code]

Regards
Huggie
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.