【问题标题】:Read from array PHP从数组 PHP 中读取
【发布时间】:2015-02-14 00:09:34
【问题描述】:

我正在尝试从下面的数组中提取用户 ID,但我收到了这条消息:

A PHP Error was encountered
Severity: Notice
Message: Undefined index: profile_picture
Filename: views/profile_view.php
Line Number: 52

数组:

array (size=1)
  'profile_picture' => 
    array (size=1)
      0 => 
        object(stdClass)[21]
          public 'UserID' => string '43' (length=2)
          public 'PictProfFlag' => string '1' (length=1)
          public 'PictPath' => string 'http://cms/uploads/category_icon.png' (length=36)

我是这样打印的:

            foreach($profile_picture as $row)
            {
                echo $row->UserID;
            }

我正在使用 Codeigniter 框架。

请帮忙

【问题讨论】:

  • 你确定不是这样的:foreach($array['profile_picture'] as $row) {
  • 你能解释一下什么是 $profile_picture 吗?
  • 你能在进入循环之前显示代码吗?

标签: php arrays codeigniter


【解决方案1】:

我刚刚解决了我的问题。

我正在从以下模型中检索数据:

控制器:

$this->get_user_pictures($id);

型号:

$data['profile_picture'] = $this->profile_model->picture($id);

并返回数组 $data 而不是 $data['profile_picture']

现在可以了,谢谢

【讨论】:

  • 其他人将如何理解您需要从您的问题中获得此解决方案?您不应输入此答案,因为答案与问题无关。您可以将其作为您已解决的评论。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-15
  • 2016-06-18
相关资源
最近更新 更多