Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first problem you are seeing is that this line is not doing quite what you want:</p> <pre><code>$hotel_array[$id] = $entry2-&gt;attributes()-&gt;HOTEL_CODE; </code></pre> <p>Whenever you access a child element or attribute of a SimpleXML object, what you get back is another SimpleXML object. So at the end of this statement, <code>$hotel_array[$id]</code> points to a SimpleXML object. Then when you try to assign other details to <code>$hotel_array[$id]</code>, PHP thinks you are trying to modifying the XML itself in an unsupported way, leading to the error you're seeing.</p> <p>What I think you actually want is to get the <em>content</em> of that attribute, as a plain PHP string. The way to do that is to cast to string with <code>(string)$variable</code>:</p> <pre><code>$hotel_array[$id] = (string)$entry2-&gt;attributes()-&gt;HOTEL_CODE; </code></pre> <p>However, you then have a second problem: <code>$hotel_array[$id]</code> is now a string, but a few lines later you try to treat it as an array:</p> <pre><code>$hotel_array[$id]['rooms'][$i] = $room_array; </code></pre> <p>Looking at the code, <code>$id</code> is already set to <code>(string)$entry2-&gt;attributes()-&gt;HOTEL_CODE</code>, and is stored as the key of the <code>$hotel_array</code> entry, so I'm not sure why you need to assign it again at all, but if you do, it can't go in the same place as the array containing the <code>['rooms']</code> key. Instead, you want one of these lines:</p> <pre><code># Just create an empty hash with the key as the hotel code $hotel_array[$id] = array(); # Add the hotel code into the array, next to the 'rooms' key $hotel_array[$id]['code'] = (string)$entry2-&gt;attributes()-&gt;HOTEL_CODE; # Above combined into one array initialisation, including empty 'rooms' array $hotel_array[$id] = array( 'code' =&gt; (string)$entry2-&gt;attributes()-&gt;HOTEL_CODE, 'rooms' =&gt; array() ); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload