2011-01-19 8 views
3

複雑な質問です...:array_key_double配列のPHP

EDIT !!

私は...これを試してみました:...

しかし、それは動作しません:

if ($citation->MeshHeadingList) 
      {//b 

       foreach ($citation->MeshHeadingList->MeshHeading as $mesh_heading) 
       {//c 
       $mesh_tag = $mesh_heading->DescriptorName; 
       //If Qualifier name excists: 
       if (isset($mesh_heading->QualifierName)) 
        {//d 


        if (!array_key_exists($mesh_tag, $mesh_tags_array)) 
         {//e 
         $mesh_tags_array[$mesh_tag][] = 0; 
         foreach ($mesh_heading->QualifierName as $qualifier_name) 
          {//f 
           if (!array_key_exists($qualifier_name, $mesh_tags_array) 
            {//g 
            $mesh_tags_array[][$qualifiername] = 0; 
            }//g 
           else 
            {//g 
            $mesh_tags_array[][$qualifiername] += 1; 
            }//g 
          }//f 

         if ($mesh_heading->DescriptorName->attributes() == "Y") 
          {//f 
          $major = 3; 
          }//f 
          else 
          {//f 
          $major = 0; 
          }//f 
         $mesh_tags_array[$mesh_tag][] += $position_rank + $date_rank + $major; 

         }//e 

        else 
         {//e 
         if ($mesh_heading->DescriptorName->attributes() == "Y") 
          {//f 
          $major = 3; 
          }//f 
         else 
          {//f 
          $major = 0; 
          }//f     
         if (!array_key_exists($mesh_tag, $mesh_tags_array)) 
          {//f 
          $mesh_tags_array[$mesh_tag][] = 0; 
          }//f 
         else 
          {//f 
          $mesh_tags_array[$mesh_tag][] += $position_rank + $date_rank + $major; 
          }//f 

         }//e 

        }//d 
       }//c 
      }//b 
      else 
      {//b 
      echo "mesheading is missing in article " . $i . "<br />"; 

      }//b 

そして、ここでのXmlObject:

[MeshHeadingList] => SimpleXMLElement Object 
          (
           [MeshHeading] => Array 
            (
             [0] => SimpleXMLElement Object 
              (
               [DescriptorName] => Acoustic Stimulation 
               [QualifierName] => methods 
              ) 

             [1] => SimpleXMLElement Object 
              (
               [DescriptorName] => Adult 
              ) 

             [2] => SimpleXMLElement Object 
              (
               [DescriptorName] => Auditory Perception 
               [QualifierName] => physiology 
              ) 

             [3] => SimpleXMLElement Object 
              (
               [DescriptorName] => Electroencephalography 
               [QualifierName] => methods 
              ) 

             [4] => SimpleXMLElement Object 
              (
               [DescriptorName] => Event-Related Potentials, P300 
               [QualifierName] => Array 
                (
                 [0] => genetics 
                 [1] => physiology 
                ) 
        ) 
        [5] => SimpleXMLElement Object 
              (
               [DescriptorName] => Schizotypal Personality Disorder 
               [QualifierName] => Array 
                (
                 [0] => diagnosis 
                 [1] => genetics 
                 [2] => psychology 
                 [3] => clinical physiology 
                ) 

              ) 

       [MeshHeading] => Array 
            (
             [0] => SimpleXMLElement Object 
              (
               [DescriptorName] => Adolescent 
              ) 


        [1] => SimpleXMLElement Object 
              (
               [DescriptorName] => Event-Related Potentials, P300 
               [QualifierName] => Array 
                (
                 [0] => genetics 
                 [1] => physiology 
          [2] => methods 
                ) 

        ) 
             [2] => SimpleXMLElement Object 
              (
               [DescriptorName] => Attention 
              ) 

             [3] => SimpleXMLElement Object 
              (
               [DescriptorName] => Female 
              ) 

             [4] => SimpleXMLElement Object 
              (
               [DescriptorName] => Genetic Predisposition to Disease 
               [QualifierName] => Array 
                (
                 [0] => genetics 
                 [1] => psychology 
                ) 

              ) 

             [5] => SimpleXMLElement Object 
              (
               [DescriptorName] => Schizotypal Personality Disorder 
               [QualifierName] => Array 
                (
                 [0] => diagnosis 
                 [1] => genetics 
                 [2] => psychology 
                ) 

              ) 

を私はしたい出力することがで次の配列:

Acoustic Stimulation (1) 
-methods (1) 

Adult (1) 

Auditory Perception (1) 
-physiology (1) 

Electroencephalography (1) 
-methods (1) 

Event-Related Potentials, P300 (2) 
-genetics (2) 
-physiology (2) 
-methods (1) 

Schizotypal Personality Disorder (2) 
-diagnosis (2) 
-genetics (2) 
-psychology (2) 
-clinical physiology (1) 

Adolescent (1) 

Attention (1) 

Female (1) 

Genetic Predisposition to Disease (1) 
-genetics (1) 
-psychology (1) 

Exp lantion:Discriptor名が存在する場合は、値1を追加します。QualifierNameが同じDiscriptorNameに存在する場合は、QualifierNameにも値を追加します。

ご覧のとおり、最初にチェックする必要があります"array_key_exists"と後で配列の配列に...?

私は1次元配列で作業していますが、これはもっと複雑です...?

よろしく、あなただけのissetを使用することができます タイス

+0

あなたが試したコードを投稿できますか? –

答えて

3

if (isset($stat[$descriptorName][$qualifierName])) 
+0

説明できますか? – Thijs

+0

私はissetを使用すると、配列がまったく同じ場合にのみ真となりますが、ディスクリプタ名は同じですが、qualifiername配列が異なる場合があります。 – Thijs