gpt4 book ai didi

php - 为什么数据只在 foreach 循环中显示,而在外部是非对象时显示?

转载 作者:行者123 更新时间:2023-11-29 00:40:28 25 4
gpt4 key购买 nike

我是 PHP 的新手,对此有点困惑..

当我有这个时,它会显示数据

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

但是当我这样做时,我得到“试图获取非对象的属性”

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

但我已经看到代码不在 foreach 循环中并显示数据。谁能帮忙解释一下这是为什么?

最佳答案

您的 foreach 应该具有 (array_expression as $value) 的格式。 source

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

关于php - 为什么数据只在 foreach 循环中显示,而在外部是非对象时显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12487449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com