dsmgcse8876 2015-05-07 20:57
浏览 33
已采纳

循环逻辑不能影响每个元素

thanks in advance for helping, and looking.

I have a bunch of images whose paths and metadata I need to process in a web directory: e.g. 'path/to/files/u_1.jpg'

$list=array_values($list);
foreach ($list as &$value)
   list($width, $height) = getimagesize($dir.$udir.$value);
   $value = $predir.$udir.$value.$wid.$width.$hgt.$height.$lft.$end;

I used scandir to get the elements into the $list array correctly.
The rest of variables, are basically creating the img tags in an html page.

However, what I get is only the last element done correctly, the rest do not come out of the loop:

Array
(
[0] => u_1.jpg
...
[16] => u_8.jpg
[17] => img src="/images/photo/up/u_9.jpg" style="display: none; width: 1526px; height: 1080px; left: 0px; top: px; ">
)

But the metadata is correctly found (image height and width for that image).

What I need is to get every line to look like the last. I have searched but I think this may be a fundamental logic issue. Is there a way to pass the info to another holding array, or something along those lines?

  • 写回答

2条回答 默认 最新

  • doutuichan2681 2015-05-07 21:02
    关注

    Without {} foreach will consider on the next line to it. So only for the last element the values are set. Put {}s so that the foreach know what to process. Try with -

    foreach ($list as &$value) {
       list($width, $height) = getimagesize($dir.$udir.$value);
       $value = $predir.$udir.$value.$wid.$width.$hgt.$height.$lft.$end;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 DevEco studio开发工具 真机联调找不到手机设备
  • ¥15 请教前后端分离的问题
  • ¥100 冷钱包突然失效,急寻解决方案
  • ¥15 下载honeyd时报错 configure: error: you need to instal a more recent version of libdnet
  • ¥15 距离软磁铁一定距离的磁感应强度大小怎么求
  • ¥15 霍尔传感器hmc5883l的xyz轴输出和该点的磁感应强度大小的关系是什么
  • ¥15 vscode开发micropython,import模块出现异常
  • ¥20 Excel数据自动录入表单并提交
  • ¥30 silcavo仿真,30分钟,只需要代码
  • ¥15 FastReport 怎么实现打印后马上关闭打印预览窗口
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部