Remove a child with a specific attribute, in SimpleXML for PHP

后端 未结 17 2595
星月不相逢
星月不相逢 2020-11-22 02:50

I have several identical elements with different attributes that I\'m accessing with SimpleXML:


    
    

        
17条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 03:04

    A new idea: simple_xml works as a array.

    We can search for the indexes of the "array" we want to delete, and then, use the unset() function to delete this array indexes. My example:

    $pos=$this->xml->getXMLUser();
    $i=0; $array_pos=array();
    foreach($this->xml->doc->users->usr[$pos]->u_cfg_root->profiles->profile as $profile) {
        if($profile->p_timestamp=='0') { $array_pos[]=$i; }
        $i++;
    }
    //print_r($array_pos);
    for($i=0;$ixml->doc->users->usr[$pos]->u_cfg_root->profiles->profile[$array_pos[$i]]);
    }
    

提交回复
热议问题