Preferably, convert the json data to native PHP Object and then using foreach, loop over the object and extracting the ID of the Objects that match the given SSN Number. The result of the extraction would be assigned to an array. Below is a Commented procedure of 1 possible way of going about this:
<?php
// WE ASSUME, JUST FOR TESTING PURPOSES THAT THE SSN NUMBER WE ARE LOOKING FOR IS 4567
$ssnNumber = 4567; //3455;
// CREATE A NEW ARRAY VARIABLE TO HOLD THE IDs YOU DESIRE & INITIALIZE IT TO AN EMPTY ARRAY
$arrIDS = array();
$jsonData = '[
{
"id" :1.25,
"name" :"rose",
"Number" :15,
"SSN" :[
12345,
3455
]
},
{
"id" :1.15,
"name" :"orchid",
"Number" :7,
"SSN" :[
12345,
3455
]
},
{
"id" :1.75,
"name" :"orchid",
"Number" :79,
"SSN" :[
4567,
89012
]
}
]';
// CONVERT $jsonData TO NATIVE PHP OBJECT
$objJson = json_decode($jsonData);
// LOOP THROUGH THE PHP OBJECT & TEST IF A GIVEN SSN EXIST.
foreach($objJson as $key=>$data){
// CHECK IF THE $data->SSN IS SET:
if(isset($data->SSN) && is_array($data->SSN)){
// CHECK IF THE SSN ARRAY CONTAINS THE GIVEN SSN NUMBER.
if(in_array($ssnNumber, $data->SSN)){
$arrIDS[] = $data->id;
}
}
}
var_dump($arrIDS); // DISPLAY: array (size=1) 0 => float 1.75
Alternatively, one could as well encapsulate the above Routine withina Function for re-usability like so:
<?php
function getIDBySSN($jsonData, $ssnNumber){
$arrIDs = array();
$objJson = json_decode($jsonData);
// LOOP THROUGH THE PHP OBJECT & TEST IF A GIVEN SSN EXIST.
foreach($objJson as $key=>$data){
// CHECK IF THE $data->SSN IS SET:
if(isset($data->SSN) && is_array($data->SSN)){
// CHECK IF THE SSN ARRAY CONTAINS THE GIVEN SSN NUMBER.
if(in_array($ssnNumber, $data->SSN)){
$arrIDs[] = $data->id;
}
}
}
return $arrIDs;
}
var_dump(getIDBySSN($jsonData, $ssnNumber)); // PRODUCES THE SAME RESULT
Test it HERE: