Properties 注意:中未定义的属性:stdClass::$images

Properties 注意:中未定义的属性:stdClass::$images,properties,undefined,stdclass,notice,Properties,Undefined,Stdclass,Notice,我对stdObject有问题。我没有找到解决我问题的办法。有些产品有图像 [products] => array ( [0] => stdClass Object ( [images] => Array ( [0] => stdClass Object

我对stdObject有问题。我没有找到解决我问题的办法。有些产品有图像

[products] => array
     (
         [0] => stdClass Object
             (
                 [images] => Array
                     (
                         [0] => stdClass Object
                             (
                                 [original_url] => /path/to/the/picture.jpg
但也有一些产品没有图像,[original_url]=>/path/to/the/picture.jpg不存在。如何检查[original_url]=>/path/to/the/picture.jpg是否不存在

foreach($product->images as $images){

    $PIC_url = $images->original_url;

    if(!property_exists($images,'original_url')){   


        $whole_pic_url = 'https://path.to/alternative/picture.jpg';

    } else {

        $whole_pic_url = "https://www.path.to".$PIC_url . ',';

    }
}


向dashmir致意

我找到了问题的解决方案-我将此代码放在foreach循环之前

if(property_exists($product, "images")){

        foreach($product->images as $images){


            $PIC_url = $images->original_url;



                $whole_pic_url = "https://www.path.to".$PIC_url . ',';

                echo "<pre>";
                    var_dump ($whole_pic_url);
                echo "</pre>";
        }
    } else {

        $whole_pic_url = 'https://path.to/alternative/picture.jpg';

    }
if(属性_存在($product,“images”)){
foreach($product->图像作为$images){
$PIC_url=$images->original_url;
$whole_pic_url=”https://www.path.to“$PIC_url.”;
回声“;
变量转储($whole\u pic\u url);
回声“;
}
}否则{
$whole\u pic\u url='1https://path.to/alternative/picture.jpg';
}
供参考

致意 达什米尔