dth8312 2014-03-26 11:10
浏览 5
已采纳

带有不同数字的未定义偏移量

I am trying to explode some links, but some of them contain 7 / and some of them have 6 / Therefor I get error Notice: Undefined Offset 7, how can I overcome this:

$imagethumb = array('6 slashes in url','7 slashes'); // this is just for simulating
$imagethumbs = explode('/', $imagethumb);
$thumbname = $imagethumbs[7];
  • 写回答

2条回答 默认 最新

  • douyue7536 2014-03-26 11:12
    关注

    Always choose the latest entry in the array.

    You can count the amount of indexes using the count() function.

    You code should look like this: $thumbname = $imagethumbs[count($imagethumbs) - 1];

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥200 如何使用postGis实现最短领规划?
  • ¥15 pyinstaller打包错误
  • ¥20 cesm的气溶胶排放文件
  • ¥15 逐月累计,月份不连续,补齐月份
  • ¥15 应用简单的Python代码完成一个学生成绩管理系统
  • ¥15 用matlab求微分方程初值问题
  • ¥15 vscode下编写第三方库opencv与pcl代码时没有代码提示
  • ¥15 能够跑通不报错,如何解决?(标签-matlab)
  • ¥15 MOS在RDS较大,频率高时开关波形异常
  • ¥15 SCENIC分析报错求解答