May 3, 2008
Echo PHP Nested Array Contents + Keys
I’ve always had some trouble with the syntax for accessing Nested Arrays and their Keys in PHP so I wanted to make note of this.
Structure is as follows:
print_r $contents;
([Cutbacks.jpg] => Array ( [time] => 1207637110 [hash] => 05dee882129fe1574bcc8379ad3a40ac [size] => 43928 ) [matrix3.zip] => Array ( [time] => 1208040588 [hash] => 5f317404880304b82e9502fb399f2737 [size] => 46790 ) )
Code:
foreach( $contents as $key => $list ) {
echo 'Filename: ' . $key . "\n";
echo 'Time: ' . $list[time] . "\n";
echo 'Hash: ' . $list[hash] . "\n";
echo 'Size: ' . $list[size] . "\n";
echo '----Next File----' . "\n";
}
Outputs:
Filename: Cutbacks.jpg Time: 1207637110Hash: 05dee882129fe1574bcc8379ad3a40ac Size: 43928 ----Next File---- Filename: matrix3.zip Time: 1208040588 Hash: 5f317404880304b82e9502fb399f2737 Size: 46790 ----Next File----
No Comments, Comment or Ping
Reply to “Echo PHP Nested Array Contents + Keys”