-1

i have a problem with a stdObject. i did not find a solution for my problem. there are products that have images

[products] => array
     (
         [0] => stdClass Object
             (
                 [images] => Array
                     (
                         [0] => stdClass Object
                             (
                                 [original_url] => /path/to/the/picture.jpg

But there are also products that have no images and [original_url] => /path/to/the/picture.jpg does not exist. How can I check if [original_url] => /path/to/the/picture.jpg does not exist?

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 . ',';

    }

}

best regards dashmir

1 Answers1

0

i found the solution for my question -I put this code before the foreach loop.

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';

    }

FYI

Best regards Dashmir