Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

php - 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

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";
    }
?>
question from:https://stackoverflow.com/questions/65848143/how-to-used-the-id-which-got-using-get-method-i-want-to-match-that-id-by-searchi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<?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>";   
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...