I have this array... how do you print each of the filepath and filename? What is the best way to do this?
Array (
[0] => Array (
[fid
Using foreach
loop without key
foreach($array as $item) {
echo $item['filename'];
echo $item['filepath'];
// to know what's in $item
echo ''; var_dump($item);
}
Using foreach
loop with key
foreach($array as $i => $item) {
echo $item[$i]['filename'];
echo $item[$i]['filepath'];
// $array[$i] is same as $item
}
Using for
loop
for ($i = 0; $i < count($array); $i++) {
echo $array[$i]['filename'];
echo $array[$i]['filepath'];
}
var_dump
is a really useful function to get a snapshot of an array or object.