jeudi 27 juin 2019

Undefined Index - even though it seems to be defined? HELP, PLEASE :)

This is absolutely driving me insane, when i try to define the the filename within my array, using an index from the feed 'url' i get 'Undefined Index'

XML

    <images>
        <image id="1"><url>https://media.inmobalia.com/imgV1/B98Le8~d7M9k3DegpEFZhS0lI_F8U4XZVz~HWxt~mGgYekxX9nCAxh0ZipZlAjNxEM6s1ur~IyRoHkUHvRIKXOjuLeAihIByqSrPmMwRzskZNx1a12uD1e5Q9J3VkMbNMIhcfXGgDMEAXDNSVEZu.jpg
            </url>
        </image>
        ...

PHP

//Get the urls form images   
    public function collectKyeroImages($imagesData){
        //dd($imagesData);
        \Log::info("Collecting Images");

        $images = [];

        foreach ($imagesData as $image){
        //            dd($image);
            $obj = [
                'filename' => $image
                ];
                    $images[] = $obj;
                }

                dd($images);

            return $images;
    }

DD Result -

array:19 [
  0 => array:1 [
    "filename" => array:2 [
      "@attributes" => array:1 [
        "id" => "1"
      ]
      "url" =>"https://media.inmobalia.com/imgV1/B98Le8~d7M9k3DegpEFZhS0lI_F8U4XZVz~HWxt~mGgYekxX9nCAxh0ZipZlAjNxEM6s1ur~IyRoHkUHvRIKXOjuLeAihIByqSrPmMwRzskZNx1a12uD1e5Q9J3VkMbNMIhcfXGgDMEAXDNSVEZu.jpg"
    ]
 ]

Approach

        if (isset($val['images'])) {$pictures = $this->collectKyeroImages($val['images']['image']);} elseif (isset($val['images']['image'])) 

        public function collectKyeroImages($imagesData){
            //dd($imagesData);
            \Log::info("Collecting Images");
                foreach ($imagesData as $image){
        //            dd($image);
                    $obj = [
                    'filename' => $image['url']
                    ];
                $images[] = $obj;
            }
        //dd($images);

        return $images;

        }

Result = Undefined index;



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire