-1

How to used the id which got using GET method i want to match that id by searching array which i provided to edit that data and make it a new one

<?php
    $json = file_get_contents('data.json');
    $json = json_decode($json,true);
    $user_id=$_GET['id'];
    echo "$user_id<br>";
    // $new = array_keys($json);
    echo "<pre>";
    echo print_r($json);
    echo "</pre>";
    if ($user_id ==  ????) {
        echo "true";
    }
    else{
        echo "false";
    }
?>
Harris
  • 59
  • 5
  • 1
    Does this answer your question? [How do I extract data from JSON with PHP?](https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php) – El_Vanja Jan 22 '21 at 15:40
  • Is there anything not working with the given code? Where's your attempt to search anything from that JSON data? – Nico Haase Jan 23 '21 at 14:00
  • yes actually as u can see the code i want to use the $user_id and compare it with id prsent in json file and show the record of the id matched with each other Rn i am stuck here need some guideance – Harris Jan 25 '21 at 14:37

1 Answers1

0
<?php
    $json = file_get_contents('data.json');
    $json = json_decode($json,true);
    $user_id=$_GET['id'];
    $person = array_filter($json,function($items) use ($user_id) {
        return $items['id'] == $user_id;
    });
    echo "<pre>";
    print_r($person);
    echo "<pre>";   
?>
Harris
  • 59
  • 5
  • This what is wanted to do now it will get id from the record which i gave by using unique funtion after that it will comapare it with all the data present in json and now i can print that specfic data into input lable and change it and then save it into json again – Harris Jan 25 '21 at 17:41