title: PHP Search JSON File and get result
body: <p>Here is my JSON File that contains my items. I would like to search for the item name and return the id.</p>
  
  <p>CODE:</p>
  
  <pre><code> $jsonitem = file_get_contents("data.json");
  
   $objitems = json_decode($jsonitem);
  
  
   $findById = function($id) use ($objname) {
    foreach (json_decode($objname) as $friend) {
      if ($friend-&gt;id === $id) return $friend-&gt;name;
    }
    return;
  };
  
  echo $findById('6') ?: 'No record found.';
  </code></pre>
  
  <p>JSON FILE:</p>
  
  <pre><code>[
         {
            "id":1,
            "name":"Candy Wrapper",
            "value":500,
         },
         {
            "id":2,
            "name":"Torch",
            "value":2000,
         }
      ]
  </code></pre>