fork download
  1. <?php
  2.  
  3. $input = json_decode(file_get_contents("php://stdin"), false);
  4.  
  5. //Get the key of the match
  6. $key = array_search('test2', array_column($input, 'name'));
  7.  
  8. //Get the id beloning to the name
  9. $id = $input[$key]->id;
  10.  
  11.  
  12. echo $id;
Success #stdin #stdout 0.01s 24416KB
stdin
[
  {
    "id": "1",
    "name": "test1"
  },
  {
    "id": "2",
    "name": "test2"
  }
]
stdout
2