【问题标题】:I've got Undefined offset: 9 .Line Number: 42 from $string我有 Undefined offset: 9 .Line Number: 42 from $string
【发布时间】:2015-05-07 04:52:14
【问题描述】:

我一整天都在寻找解决此问题的方法。 当我尝试调试时,出现如下消息:

块引用 消息:未定义的偏移量:9 | 文件名:views/view_viewnews.php | 行号:42

        <?php
            echo '<span id ="title">'.$string[0][4].'</span>';
            $date_str = $string[0][9];
            $date_str=substr($date_str,0,10);
            echo '<span id ="author">'.$string[1][0].' /'.$date_str.'</span>'; 
        ?>

我哪里会出错?任何帮助?谢谢!

【问题讨论】:

  • 你能说一下 $date_str 的值是多少吗?
  • var_dump($string) 看看里面有什么。
  • 是的,我使用了 $string = json_decode($jsonfile,true);

标签: php html string offset


【解决方案1】:
$date_str = $string[0][9];

您没有数组 $string[0] 的第 10 个值的值

这就是为什么。

【讨论】:

  • 嗯。让我从 jsonfile 仔细检查。我;从那里得到了价值。如果只是,我只有 6 个值,那么 $date_str = $string[0][5]; ?
  • 对。数组从 0 开始。如果您期望第 9 个值,则应该“询问”第 8 个值。
  • @LinaLyn 通过单击检查将答案设置为已解决,谢谢。
猜你喜欢
  • 1970-01-01
  • 2016-08-23
  • 1970-01-01
  • 2022-12-19
  • 2023-01-31
  • 1970-01-01
  • 1970-01-01
  • 2020-08-20
  • 2013-09-23
相关资源
最近更新 更多