1

Изначально в xml выглядит следующим образом:

<?xml version="1.0" encoding="UTF-8"?>
 <Title date="2012-07-23T17:36:00">
   <Group name="Cabinet" code="10" parent="5"/>
 </Title>

Дошел до этого

   object(SimpleXMLElement)#64 (1) {
  ["@attributes"]=>
  array(3) {
    ["name"]=>
    string(7) "Cabinet"
    ["code"]=>
    string(6) "10"
    ["parent"]=>
    string(6) "5"
  }
}

Как получить значения элементов name, code, parent из массива, который лежит в объекте object(SimpleXMLElement)#64?

1 ответ 1

2

Я пользуюсь такой функцией... а потом работаю уже с массивом

//Convert Object to Array

function objectToArray($object)        
{
    if (is_object($object))
    {    
        $object = get_object_vars($object);    
    }

    if (is_array($object))
    {
        return array_map( array($this, __FUNCTION__), $object );
    }
    else
    {
        return $object;
    }
}
1
  • 1
    Спасибо за функцию! Помогло) 26 июл 2012 в 10:09

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.