dpfln86244 2012-09-19 01:39
浏览 62
已采纳

为什么数据仅在foreach循环中显示但在其外部是非对象?

I'm new to PHP and confused about this bit ..

When I have this it shows the data

<?php foreach ($profile as $p):?>
    <?php echo $profile->custom_url;?>
                    <?php endforeach?>

But when I do this I get " Trying to get property of non-object"

   <?php echo $profile->custom_url;?>

yet I have seen code where it's not in a foreach loop and the data displays. Can anybody help explain why that is?

  • 写回答

2条回答 默认 最新

  • draj840143 2012-09-19 01:42
    关注

    Your foreach should have the format of (array_expression as $value). source

    <?php foreach ($profile as $p):?>
    <?php echo $p->custom_url;?>
    <?php endforeach?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图
  • ¥15 UE5.1局部变量对蓝图不可见
  • ¥15 一共有五道问题关于整数幂的运算还有房间号码 还有网络密码的解答?(语言-python)
  • ¥20 sentry如何捕获上传Android ndk 崩溃
  • ¥15 在做logistic回归模型限制性立方条图时候,不能出完整图的困难
  • ¥15 G0系列单片机HAL库中景园gc9307液晶驱动芯片无法使用硬件SPI+DMA驱动,如何解决?