I have a little problem with my json file, what I am trying to do is get the specific object from my json file, so in this json above when i add this parameter stream_id= and for example i add this id stream_id=200 it should show only the object with that id, so to be more clear it should show id:200, name:Ravi Tamada, email:[email protected] etc etc ,with PHP, thanks
{
"contacts": [
{
"id": "200",
"name": "Ravi Tamada",
"email": "[email protected]",
"address": "xx-xx-xxxx,x - street, x - country",
"gender" : "male",
"url": "http://149.202.196.143:8000/live/djemal/djemal/592.ts"
},
{
"id": "201",
"name": "Johnny Depp",
"email": "[email protected]",
"address": "xx-xx-xxxx,x - street, x - country",
"gender" : "male",
"url":"http://149.202.196.143:8000/live/djemal/djemal/592.ts"
},
{
"id": "202",
"name": "Leonardo Dicaprio",
"email": "[email protected]",
"address": "xx-xx-xxxx,x - street, x - country",
"gender" : "male",
"url":"http://149.202.196.143:8000/live/djemal/djemal/592.ts"
}
]
}
You could iterate through your JSON and look for the Id you need. Simple as that.
$json = /* your json */;
$array = json_decode($json, true);
$result = getInfo(200, $array);
function getInfo($id, $array) {
foreach($array AS $index => $element) {
if($element['id'] == $id) {
return $element;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With