Problem image more than one and get limitation in xml child with php

i have xml the other array i got it but first one cant how can i solve this

Xml structure like this and get an error code in xml to php First one is not array the second one is array

i Coudnt get the first image children "sitename/11.jpg"

<root>  <images> <image>sitename/15.jpg</image><image>sitename/16.jpg</image><image>sitename/17.jpg</image><image>sitename/18.jpg</image> </images>  <images> <image>sitename/11.jpg</image> </images> <root/>   [images] => SimpleXMLElement Object ( [image] => Array ( [0] => sitename/15.jpg [1] => sitename/16.jpg [2] => sitename/17.jpg [3] => sitename/18.jpg ) ) )  [images] => SimpleXMLElement Object ( [image] => sitename/11.jpg ))   function solve_something($xml, $destination) {     $xml = simplexml_load_file($xml, "SimpleXMLElement", LIBXML_NOCDATA);     $json = json_encode($xml);     $items = json_decode($json, TRUE);     $products = array();     $product_data = array();     $row = 1;      if (isset($item['images']['image'])) {         if (is_array($item['images']['image'])) {             foreach ($item['images']['image'] as $key => $image) {                 $key++;                 if ($key <= 4) {                     $image_name = 'image' . $key;                     $product_data[$image_name] = isset($image) ? $image : null;                 }             }         } else {             $product_data['image'] = isset($image) ? $image : null;         }     }  $path = createXML($products, $destination); return $path; }  

Code print

<images> <image1>sitename/15.jpg <image2>sitename/16.jpg <image3>sitename/17.jpg </images> <images> <image1>sitename/15.jpg <image2>sitename/16.jpg <image3>sitename/17.jpg <image4>sitename/18.jpg </images> 

But i want

<images> <image1>sitename/15.jpg <image2>sitename/16.jpg <image3>sitename/17.jpg </images> <images> <image1>sitename/11.jpg </images> 
Asked on July 16, 2020 in XML.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.