XML parser and PHP Variables

60 views Asked by At

i've created a complex script for parser datas from XML.

At the end of this, i have this:

     $xmlArray['Event'][$k]['Name event']= $nameVal;    

     $xmlArray['Event'][$k][$i]['Type event']= $typeVal;                              

If i try to parse datas with

     echo '<pre>';
     print_r($xmlArray);
     echo '</pre>';

Seems to be ok.

Now i need to save this data for Wordpress variables. Im trying with this but not works:

foreach($xmlArray as $k => $v){
    if(is_array($v) && count($v) > 0){

        foreach($v as $key => $value){  
        $event = array();
        $name = $value['Name Event']; --> IS OK
        $type = $value[$event][$key]['Type event']; --> Not work, i get error Illegal offset

        echo "$name<br>";           
        echo "$type<br>";           

    }
} else {


}

How can i fix it ??

1

There are 1 answers

2
Marc B On

You're using an empty array as a key:

    $event = array();

    $type = $value[$event][$key]['Type event'];
                   ^^^^^^---array()

Array keys can only be strings or numbers. You can't use an object, you can't use another array, etc..