Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Adding <code>'mode' =&gt; 'simplexml'</code> to $serializer_options should to it:</p> <pre><code>$serializer_options = array( XML_SERIALIZER_OPTION_INDENT =&gt; ' ', XML_SERIALIZER_OPTION_RETURN_RESULT =&gt; TRUE, 'rootName' =&gt; 'JZ_2103', 'mode' =&gt; 'simplexml', ); </code></pre> <p>Or using constants,</p> <pre><code>$serializer_options = array( XML_SERIALIZER_OPTION_INDENT =&gt; ' ', XML_SERIALIZER_OPTION_RETURN_RESULT =&gt; TRUE, XML_SERIALIZER_OPTION_ROOT_NAME =&gt; 'JZ_2103', XML_SERIALIZER_OPTION_MODE =&gt; XML_SERIALIZER_MODE_SIMPLEXML, ); </code></pre> <p>Found it <a href="http://pear.php.net/package/XML_Serializer/docs/0.20.2/__filesource/fsource_XML_Serializer__XML_Serializer-0.20.2XMLSerializer.php.html#a428" rel="nofollow">here</a> on line 515.</p> <blockquote> <p>// use XML_SERIALIZER_MODE_SIMPLEXML to use parent name as tagname</p> <p>// if transforming an indexed array</p> <pre><code>XML_SERIALIZER_OPTION_MODE =&gt; XML_SERIALIZER_MODE_DEFAULT, </code></pre> </blockquote> <p><strong>EDIT</strong>: updated to point to actual XML_Serializer codebase.</p> <p>Changes should be made to the code as follows (thanks to @danielpsc, see comments):</p> <pre><code>$otXmlArr = array( 'status' =&gt; 'success', 'reason' =&gt; 'null', 'payload' =&gt; array( 'ContactsResponse' =&gt; array( 'Contact' =&gt; array() ) ) ); foreach ($mydata as $item) { array_push($otXmlArr['payload']['ContactsResponse']['Contact'], array( 'ID' =&gt; $item['id'], 'FirstName' =&gt; $item['fname'] ) ); } </code></pre> <p><strong>EDIT2</strong>: Made changes to code</p>
    singulars
    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. This table or related slice is empty.
    1. 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