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:
[sourcecode language=”php”]
print_r $contents;[/sourcecode]
([Cutbacks.jpg] => Array
(
[time] => 1207637110
[hash] => 05dee882129fe1574bcc8379ad3a40ac
[size] => 43928
)
[matrix3.zip] => Array
(
[time] => 1208040588
[hash] => 5f317404880304b82e9502fb399f2737
[size] => 46790
)
)
Code:
([Cutbacks.jpg] => Array
(
[time] => 1207637110
[hash] => 05dee882129fe1574bcc8379ad3a40ac
[size] => 43928
)
[matrix3.zip] => Array
(
[time] => 1208040588
[hash] => 5f317404880304b82e9502fb399f2737
[size] => 46790
)
)
Code:
[sourcecode language=”php”]
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";
}[/sourcecode]
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";
}[/sourcecode]
Outputs:
Filename: Cutbacks.jpg Time: 1207637110Hash: 05dee882129fe1574bcc8379ad3a40ac Size: 43928 ----Next File---- Filename: matrix3.zip Time: 1208040588 Hash: 5f317404880304b82e9502fb399f2737 Size: 46790 ----Next File----
0 comments:
Post a Comment