title: Changes to array of JSON objects based on other array
body: <p>I have an array of JSON objects that look like this:</p>
  
  <pre><code>{"id":1,"place":2,"pic_name":"aaa.jpg"}
  </code></pre>
  
  <p>My PHP file receives a simple array like:</p>
  
  <pre><code>["4","3","1","2","5"]
  </code></pre>
  
  <p>These numbers correspond to the place value in my JSON object. Now I need to compare the place of each element in the secont array with the value of ID in the JSON object and if the match I have to replace the value of PLACE with the element from the array.
  I am having problems doing the comparison. Any guidelines? What I come up with:</p>
  
  <pre><code>foreach($ids as $index=&gt;$id) { //the array
  $id = (int) $id;
  foreach ($obj as $key=&gt;$value) { //the JSON objects
    foreach ($value as $k=&gt;$v){ 
    if ($id != '' &amp;&amp; array_search($index, array_keys($ids)) == $value[$k]['id'])  {
        $value[$k]['place'] = $id;
        file_put_contents($file, json_encode($ids));
      } else { print "nope";}  
    }  }  }
  </code></pre>