-1

I have an array which returns the information below. I'm trying to get the [Url] link from that and use it for my image, how can i do that? sorry i'm quite new to all this.

The converted array is:
object(stdClass)#4653 (9) { [“sizes”]=> object(stdClass)#4658 (3) { [“thumbnail”]=> object(stdClass)#4617 (4) { [“height”]=> int(150) [“width”]=> int(150) [“url”]=> string(60) “https://magdek.loc/app/uploads/2022/03/slide-1-2-150×150.jpg” [“orientation”]=> string(9) “landscape” } [“medium”]=> object(stdClass)#4659 (4) { [“height”]=> int(300) [“width”]=> int(300) [“url”]=> string(60) “https://magdek.loc/app/uploads/2022/03/slide-1-2-300×300.jpg” [“orientation”]=> string(9) “landscape” } [“full”]=> object(stdClass)#4629 (4) { [“url”]=> string(52) “https://magdek.loc/app/uploads/2022/03/slide-1-2.jpg” [“height”]=> int(311) [“width”]=> int(311) [“orientation”]=> string(9) “landscape” } } [“mime”]=> string(10) “image/jpeg” [“type”]=> string(5) “image” [“subtype”]=> string(4) “jpeg” [“id”]=> int(155) [“url”]=> string(52) “https://magdek.loc/app/uploads/2022/03/slide-1-2.jpg” [“alt”]=> string(0) “” [“link”]=> string(52) “https://magdek.loc/product/hot-air-dryers/slide-1-3/” [“caption”]=> string(0) “”

I'm using a foreach loop and the $item returns the code above but i'm not sure how to get the image from it just.

This is the code i have so far for this:

<?php
        $my_array = json_decode($args['images']);
      ?>
      <picture-gallery>
        <?php if(($my_array)):
        foreach($my_array as $item): ?>
        <div class="swiper-slide">
          <?php var_dump($item);?>
        </div>
        <?php
          endforeach;
          endif;
        ?>
      </picture-gallery>
Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
Oggy Gru
  • 1
  • 1

1 Answers1

0

$item is object which have "sizes" object with three more objects of different sizes “thumbnail”, “medium” and “full”

You can do get your required size by change inside following code

<?php echo $item->sizes->full->url; ?>

Comment or delete <?php var_dump($item);?> inside loop and Put above line there.

Note: You need to replace ->full-> with your required size

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50