title: finding php json array index number
body: <p>I have a json file with this below format structure.</p>
  
  <pre><code>[  
   {  
      "name":"banana",
      "type":"fruit",
      "rate":10
   },
   {  
      "name":"orange",
      "type":"fruit",
      "rate":20
   },
   {  
      "name":"apple",
      "type":"fruit",
      "rate":30
   }
  ]
  </code></pre>
  
  <p>I would like to update the rate of the fruit by +1 when i match a search for it.</p>
  
  <p>1 . Read the json file</p>
  
  <pre><code> $json_file = file_get_contents('fruits.txt');
  </code></pre>
  
  <p>2 . Decoded the json file</p>
  
  <pre><code> $fruit_list=json_decode($json_file,true);
  </code></pre>
  
  <ol start="3">
  <li><p>VarDumping the Decoded json file is like this</p>
  
  <pre>
  array (size=3)
    0 => 
      array (size=3)
        'name' => string 'banana' (length=6)
        'type' => string 'fruit' (length=5)
        'rate' => int 10
    1 => 
      array (size=3)
        'name' => string 'orange' (length=6)
        'type' => string 'fruit' (length=5)
        'rate' => int 20
    2 => 
      array (size=3)
        'name' => string 'apple' (length=5)
        'type' => string 'fruit' (length=5)
        'rate' => int 30
  </pre></li>
  <li><p>Wrote a search function to search the array for fruit name</p></li>
  </ol>
  
  <pre>
  function search_by_key_and_value($array, $key, $value)
  {
      $results = array();
  
      if (is_array($array))
      {
          if (isset($array[$key]) && $array[$key] == $value)
              $results[] = $array;
  
          foreach ($array as $subarray)
              $results = array_merge($results, search_by_key_and_value($subarray, $key, $value));
      }
  
      return $results;
  
  }
  
   $result = search_by_key_and_value($fruit_list,"name",apple);
  </pre>
  
  <ol start="5">
  <li><p>when the function is supplied with fruit name the whole of json file is searched and the RESULT_MATCH is printed <code>var_dump($result)</code> is like this below</p>
  
  <pre>
      array (size=1)
            0 => 
              array (size=3)
                'name' => string 'apple' (length=5)
                'type' => string 'fruit' (length=5)
                'rate' => int 30
  </pre></li>
  <li><p><strong>How can i find the array index number as the result of array index is 0 in the result but its position in the main file point no 3 is indexed at 2 or at-least how can i update the matched retsult rate directly ?</strong></p></li>
  </ol>