Jump to content

Archived

This topic is now archived and is closed to further replies.

edg322

multi-dimensional arrays

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?

Share this post


Link to post
Share on other sites
You need a foreach loop...

[code]<?php
foreach ($a as $key => $value){
  // Do something with some_ID
  echo "{$a[$key]['some_ID']}<br>\n";
}
?>[/code]

Regards
Huggie

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.