title: array_key_exists in 2D array php
body: <p>It's a complex question...:</p>
  
  <p>EDIT!!</p>
  
  <p>I tried this...:</p>
  
  <p>But it doesn't work...:</p>
  
  <pre><code>if ($citation-&gt;MeshHeadingList)
              {//b
  
                  foreach ($citation-&gt;MeshHeadingList-&gt;MeshHeading as $mesh_heading)
                  {//c
                  $mesh_tag = $mesh_heading-&gt;DescriptorName;
                  //If Qualifier name excists:
                  if (isset($mesh_heading-&gt;QualifierName))
                      {//d
  
  
                      if (!array_key_exists($mesh_tag, $mesh_tags_array))
                          {//e
                          $mesh_tags_array[$mesh_tag][] = 0;
                          foreach ($mesh_heading-&gt;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-&gt;DescriptorName-&gt;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-&gt;DescriptorName-&gt;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 . "&lt;br /&gt;";
  
              }//b
  </code></pre>
  
  <p>And here the xmlobject:</p>
  
  <pre><code> [MeshHeadingList] =&gt; SimpleXMLElement Object
                              (
                                  [MeshHeading] =&gt; Array
                                      (
                                          [0] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Acoustic Stimulation
                                                  [QualifierName] =&gt; methods
                                              )
  
                                          [1] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Adult
                                              )
  
                                          [2] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Auditory Perception
                                                  [QualifierName] =&gt; physiology
                                              )
  
                                          [3] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Electroencephalography
                                                  [QualifierName] =&gt; methods
                                              )
  
                                          [4] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Event-Related Potentials, P300
                                                  [QualifierName] =&gt; Array
                                                      (
                                                          [0] =&gt; genetics
                                                          [1] =&gt; physiology
                                                      )
                      )
                     [5] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Schizotypal Personality Disorder
                                                  [QualifierName] =&gt; Array
                                                      (
                                                          [0] =&gt; diagnosis
                                                          [1] =&gt; genetics
                                                          [2] =&gt; psychology
                                                          [3] =&gt; clinical physiology
                                                      )
  
                                              )
  
                   [MeshHeading] =&gt; Array
                                      (
                                          [0] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Adolescent
                                              )
  
  
                      [1] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Event-Related Potentials, P300
                                                  [QualifierName] =&gt; Array
                                                      (
                                                          [0] =&gt; genetics
                                                          [1] =&gt; physiology
                              [2] =&gt; methods
                                                      )
  
                      )
                                          [2] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Attention
                                              )
  
                                          [3] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Female
                                              )
  
                                          [4] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Genetic Predisposition to Disease
                                                  [QualifierName] =&gt; Array
                                                      (
                                                          [0] =&gt; genetics
                                                          [1] =&gt; psychology
                                                      )
  
                                              )
  
                                           [5] =&gt; SimpleXMLElement Object
                                              (
                                                  [DescriptorName] =&gt; Schizotypal Personality Disorder
                                                  [QualifierName] =&gt; Array
                                                      (
                                                          [0] =&gt; diagnosis
                                                          [1] =&gt; genetics
                                                          [2] =&gt; psychology
                                                      )
  
                                              )
  </code></pre>
  
  <p>i want to output it in the following array:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Explantion: If the Discriptor name exists, it adds a value of one, if the QualifierName exists in the same DiscriptorName it adds a value to the QualifierName too...</p>
  
  <p>As you can see, it must be checked in the first "array_key_exists" and later in the array in the array...?</p>
  
  <p>I got working with a one dimensional array but this is way more complex...??</p>
  
  <p>Regards,
  Thijs</p>