2015-05-14 5 views
-2

, пожалуйста, помогите мне в новом массиве. Как читать определенные значения из многомерного массива с использованием php ниже - это массив. я хочу, чтобы прочитать значения [itemBody][div][0][p] .THANKS заранееМногомерный массив

SimpleXMLElement Object 
(
    [@attributes] => Array 
     (
      [toolName] => Eqiat 
      [toolVersion] => 0.7~git 
      [adaptive] => false 
      [timeDependent] => false 
      [identifier] => ITEM_b95e4391e33aa28561b01493b6e328f8 
      [title] => match the following 
     ) 

    [stylesheet] => SimpleXMLElement Object 
     (
      [@attributes] => Array 
       (
        [href] => http://gauss.ecs.soton.ac.uk/eqiat/eqiat.css 
        [type] => text/css 
        [title] => Eqiat item styles, designed to override QTIEngine's output where appropriate 
       ) 

     ) 

    [responseDeclaration] => Array 
     (
      [0] => SimpleXMLElement Object 
       (
        [@attributes] => Array 
         (
          [identifier] => RESPONSE_question_0 
          [cardinality] => multiple 
          [baseType] => identifier 
         ) 

        [correctResponse] => SimpleXMLElement Object 
         (
          [value] => question_0_option_3 
         ) 

       ) 

      [1] => SimpleXMLElement Object 
       (
        [@attributes] => Array 
         (
          [identifier] => RESPONSE_question_1 
          [cardinality] => multiple 
          [baseType] => identifier 
         ) 

        [correctResponse] => SimpleXMLElement Object 
         (
          [value] => question_1_option_2 
         ) 

       ) 

      [2] => SimpleXMLElement Object 
       (
        [@attributes] => Array 
         (
          [identifier] => RESPONSE_question_2 
          [cardinality] => multiple 
          [baseType] => identifier 
         ) 

        [correctResponse] => SimpleXMLElement Object 
         (
          [value] => question_2_option_1 
         ) 

       ) 

      [3] => SimpleXMLElement Object 
       (
        [@attributes] => Array 
         (
          [identifier] => RESPONSE_question_3 
          [cardinality] => multiple 
          [baseType] => identifier 
         ) 

        [correctResponse] => SimpleXMLElement Object 
         (
          [value] => question_3_option_0 
         ) 

       ) 

     ) 

    [outcomeDeclaration] => SimpleXMLElement Object 
     (
      [@attributes] => Array 
       (
        [identifier] => SCORE 
        [cardinality] => single 
        [baseType] => integer 
       ) 

      [defaultValue] => SimpleXMLElement Object 
       (
        [value] => 0 
       ) 

     ) 

    [itemBody] => SimpleXMLElement Object 
     (
      [div] => Array 
       (
        [0] => SimpleXMLElement Object 
         (
          [p] => Match The Following 
         ) 

        [1] => SimpleXMLElement Object 
         (
          [@attributes] => Array 
           (
            [class] => eqiat-emi 
           ) 

          [ol] => SimpleXMLElement Object 
           (
            [@attributes] => Array 
             (
              [class] => emioptions 
             ) 

            [li] => Array 
             (
              [0] => bangalore 
              [1] => india 
              [2] => tiger 
              [3] => onion 
             ) 

           ) 

          [choiceInteraction] => Array 
           (
            [0] => SimpleXMLElement Object 
             (
              [@attributes] => Array 
               (
                [maxChoices] => 0 
                [minChoices] => 0 
                [shuffle] => false 
                [responseIdentifier] => RESPONSE_question_0 
               ) 

              [prompt] => vegetable 
              [simpleChoice] => Array 
               (
                [0] => A 
                [1] => B 
                [2] => C 
                [3] => D 
               ) 

             ) 

            [1] => SimpleXMLElement Object 
             (
              [@attributes] => Array 
               (
                [maxChoices] => 0 
                [minChoices] => 0 
                [shuffle] => false 
                [responseIdentifier] => RESPONSE_question_1 
               ) 

              [prompt] => animal 
              [simpleChoice] => Array 
               (
                [0] => A 
                [1] => B 
                [2] => C 
                [3] => D 
               ) 

             ) 

            [2] => SimpleXMLElement Object 
             (
              [@attributes] => Array 
               (
                [maxChoices] => 0 
                [minChoices] => 0 
                [shuffle] => false 
                [responseIdentifier] => RESPONSE_question_2 
               ) 

              [prompt] => country 
              [simpleChoice] => Array 
               (
                [0] => A 
                [1] => B 
                [2] => C 
                [3] => D 
               ) 

             ) 

            [3] => SimpleXMLElement Object 
             (
              [@attributes] => Array 
               (
                [maxChoices] => 0 
                [minChoices] => 0 
                [shuffle] => false 
                [responseIdentifier] => RESPONSE_question_3 
               ) 

              [prompt] => city 
              [simpleChoice] => Array 
               (
                [0] => A 
                [1] => B 
                [2] => C 
                [3] => D 
               ) 

             ) 

           ) 

         ) 

       ) 

     ) 

    [responseProcessing] => SimpleXMLElement Object 
     (
      [setOutcomeValue] => SimpleXMLElement Object 
       (
        [@attributes] => Array 
         (
          [identifier] => SCORE 
         ) 

        [baseValue] => 0 
       ) 

      [responseCondition] => Array 
       (
        [0] => SimpleXMLElement Object 
         (
          [responseIf] => SimpleXMLElement Object 
           (
            [match] => SimpleXMLElement Object 
             (
              [variable] => SimpleXMLElement Object 
               (
                [@attributes] => Array 
                 (
                  [identifier] => RESPONSE_question_0 
                 ) 

               ) 

              [correct] => SimpleXMLElement Object 
               (
                [@attributes] => Array 
                 (
                  [identifier] => RESPONSE_question_0 
                 ) 

               ) 

             ) 

            [setOutcomeValue] => SimpleXMLElement Object 
             (
              [@attributes] => Array 
               (
                [identifier] => SCORE 
               ) 

              [sum] => SimpleXMLElement Object 
               (
                [variable] => SimpleXMLElement Object 
                 (
                  [@attributes] => Array 
                   (
                    [identifier] => SCORE 
                   ) 

                 ) 

                [baseValue] => 1 
               ) 

             ) 

           ) 

         ) 

        [1] => SimpleXMLElement Object 
         (
          [responseIf] => SimpleXMLElement Object 
           (
            [match] => SimpleXMLElement Object 
             (
              [variable] => SimpleXMLElement Object 
               (
                [@attributes] => Array 
                 (
                  [identifier] => RESPONSE_question_1 
                 ) 

               ) 

              [correct] => SimpleXMLElement Object 
               (
                [@attributes] => Array 
                 (
                  [identifier] => RESPONSE_question_1 
                 ) 

               ) 

             ) 

            [setOutcomeValue] => SimpleXMLElement Object 
             (
              [@attributes] => Array 
               (
                [identifier] => SCORE 
               ) 

              [sum] => SimpleXMLElement Object 
               (
                [variable] => SimpleXMLElement Object 
                 (
                  [@attributes] => Array 
                   (
                    [identifier] => SCORE 
                   ) 

                 ) 

                [baseValue] => 1 
               ) 

             ) 

           ) 

         ) 

        [2] => SimpleXMLElement Object 
         (
          [responseIf] => SimpleXMLElement Object 
           (
            [match] => SimpleXMLElement Object 
             (
              [variable] => SimpleXMLElement Object 
               (
                [@attributes] => Array 
                 (
                  [identifier] => RESPONSE_question_2 
                 ) 

               ) 

              [correct] => SimpleXMLElement Object 
               (
                [@attributes] => Array 
                 (
                  [identifier] => RESPONSE_question_2 
                 ) 

               ) 

             ) 

            [setOutcomeValue] => SimpleXMLElement Object 
             (
              [@attributes] => Array 
               (
                [identifier] => SCORE 
               ) 

              [sum] => SimpleXMLElement Object 
               (
                [variable] => SimpleXMLElement Object 
                 (
                  [@attributes] => Array 
                   (
                    [identifier] => SCORE 
                   ) 

                 ) 

                [baseValue] => 1 
               ) 

             ) 

           ) 

         ) 

        [3] => SimpleXMLElement Object 
         (
          [responseIf] => SimpleXMLElement Object 
           (
            [match] => SimpleXMLElement Object 
             (
              [variable] => SimpleXMLElement Object 
               (
                [@attributes] => Array 
                 (
                  [identifier] => RESPONSE_question_3 
                 ) 

               ) 

              [correct] => SimpleXMLElement Object 
               (
                [@attributes] => Array 
                 (
                  [identifier] => RESPONSE_question_3 
                 ) 

               ) 

             ) 

            [setOutcomeValue] => SimpleXMLElement Object 
             (
              [@attributes] => Array 
               (
                [identifier] => SCORE 
               ) 

              [sum] => SimpleXMLElement Object 
               (
                [variable] => SimpleXMLElement Object 
                 (
                  [@attributes] => Array 
                   (
                    [identifier] => SCORE 
                   ) 

                 ) 

                [baseValue] => 1 
               ) 

             ) 

           ) 

         ) 

       ) 

     ) 

) 
+1

Это объект не массив. Преобразуйте в массив и получите доступ к значению. –

+0

Так ты сдался или один из них решил это ??? – AbraCadaver

+0

спасибо За вашу помощь я получил эту работу ниже мое решение function object2array ($ object) { return json_decode (json_encode ($ object), true); } $ data = object2array (simplexml_load_string ($ xml1)); echo '

',print_r($data),'
'; // echo $ data [itembody] [div] [0] [p]; echo $ data [itemBody] [div] [0] [p]; – Anup

ответ

0

первых преобразовать весь объект в массиве, чтобы получить доступ, а затем

' function object2array($object) { ' 
    return json_decode(json_encode($object), true); 

} $ = Данные object2array (simplexml_load_string ($ xml1));

эхо '

',print_r($data),'
'; `

Теперь я могу получить доступ с помощью echo $data[itemBody][div][0][p];

0

Try:

$element = $object->itemBody->div->0->p; 
+0

Я преобразую его в массив, поскольку он был объектом, а затем может получить доступ с помощью функции function2array ($ object) {' return json_decode (json_encode ($ object), true); } $ data = object2array (simplexml_load_string ($ xml1)); echo '

',print_r($data),'
'; ' Теперь я могу получить доступ к' echo $ data [itemBody] [div] [0] [p]; ' – Anup

0

То есть объект и itemBody это свойство, которое имеет другой объект со свойством div, который представляет собой массив объектов со свойствами, p быть один для объекта в индексе массива 0:

$result = $object->itemBody->div[0]->p; 
Смежные вопросы