通过数组php循环我有这个阵列.。如何打印每个文件路径和文件名?做这件事最好的方法是什么? Array (
[0] => Array (
[fid] => 14
[list] => 1
[data] => Array (
[alt] =>
[title] =>
)
[uid] => 1
[filename] => trucks_10785.jpg
[filepath] => sites/default/files/trucks_10785.jpg
[filemime] => image/jpeg
[filesize] => 143648
[status] => 1
[timestamp] => 1291424171
[nid] => 8
)
[1] => Array (
[fid] => 19
[list] => 1
[data] => Array (
[alt] =>
[title] =>
)
[uid] => 1
[filename] => school.jpg
[filepath] => sites/default/files/school.jpg
[filemime] => image/jpeg
[filesize] => 115355
[status] => 1
[timestamp] => 1292029563
[nid] => 8
)
[2] => Array (
[fid] => 20
[list] => 1
[data] => Array (
[alt] =>
[title] =>
)
[uid] => 1
[filename] => Life_is_wonderful_by_iNeedChemicalX.jpg
[filepath] => sites/default/files/Life_is_wonderful_by_iNeedChemicalX_0.jpg
[filemime] => image/jpeg
[filesize] => 82580
[status] => 1
[timestamp] => 1292029572
[nid] => 8
)
3 回答
LEATH
TA贡献1936条经验 获得超6个赞
foreach
foreach($array as $item) { echo $item['filename']; echo $item['filepath']; // to know what's in $item echo '<pre>'; var_dump($item);}
foreach
foreach($array as $i => $item) { echo $array[$i]['filename']; echo $array[$i]['filepath']; // $array[$i] is same as $item}
for
for ($i = 0; $i < count($array); $i++) { echo $array[$i]['filename']; echo $array[$i]['filepath'];}
var_dump
达令说
TA贡献1821条经验 获得超6个赞
array_map(function($n) { echo $n['filename']; echo $n['filepath'];},$array);
function printItem($n){ echo $n['filename']; echo $n['filepath'];}array_map('printItem', $array);
三国纷争
TA贡献1804条经验 获得超7个赞
foreach($database as $file) { echo $file['filename'] . ' at ' . $file['filepath'];}
- 3 回答
- 0 关注
- 367 浏览
添加回答
举报
0/150
提交
取消