I have Json file which contain alot of Arrays. How can i get the the array Dynamically for each person by name like the get Parameter.
JSON
I don't know what exactly you need to do (find only one match, or fetch all), but this is for both :
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$array = array(
1 => array( "Name" => "Somename1", "Lastname" => "somelastname1", "Address" => "someaddress1"),
2 => array( "Name" => "Somename2", "Lastname" => "somelastname2", "Address" => "someaddress2"),
3 => array( "Name" => "Somename3", "Lastname" => "somelastname3", "Address" => "someaddress3"),
4 => array( "Name" => "Somename4", "Lastname" => "somelastname4", "Address" => "someaddress4")
);
$data1 = json_encode($array);
//var_dump($data1);
$data = json_decode($data1, true);
//var_dump(json_decode($data1));
$myname = "Somename3";
/* one liner to get one result */
if( array_search("$myname", array_column($data, 'Name')) == true ){ echo"[ $myname found ! ]"; } else { echo"[ no data match ! ]"; }
/* loop to get all results */
foreach($data as $user){
echo $user['Name'].' '.$user['Lastname'].' '.$user['Address'].'<br/>';
}
?>