php - how to give array index a named key on runtime -


here trying use xmlserializer class convert data mysql table xml file.i want xml file this

enter image description here

for ,i need change numeric indexes 'book'.currently can generate array of following form:it has numeric indexing ,but purpose both of indexes (0 , 1) have 'book'.

enter image description here

how can change both numeric indexes 'book'??

full code:

   include('xmlserializer/xml/serializer.php');    $host='localhost';    $user='root';    $pass='';    $db='xmlserializer';     $dbh=new pdo("mysql:host=$host;dbname=$db",$user,$pass);    $sql='select lname,fname employee';    $sth=$dbh->prepare($sql);    $sth->execute();     $xml=array('library'=>array());     $i=0;    while($result=$sth->fetch(pdo::fetch_assoc)){        array_push($xml['library'],$result);     }    print_r($xml);    $serializer=new xml_serializer();      $result=$serializer->serialize($xml);    if($result===true){       file_put_contents('myxml.xml',$serializer->getserializeddata());    } 

you need set default tag in xml_serializer:

so code should be:

$options = array(       "defaulttagname"  => "book", );  $serializer = new xml_serializer($options); 

check link more information : https://pear.php.net/manual/en/package.xml.xml-serializer.xml-serializer.examples.php


Comments

Popular posts from this blog

html - height not adding height to a empty div -

Oracle SQL. How to select specific IDs where value of columns specify criteria? -

python - Robot Framework location and name of keyword -