$full_json ='{
"1stelement": {
"2ndelement": {
"elements": [
{
"test1": 383,
"test2": 100
},
{
"test1": 48,
"test2": 5
},
{
"test1": 383,
"test2": 100
},
{
"test1": 48,
"test2": 6
},
{
"test1": 383,
"test2": 100
},
{
"test1": 48,
"test2": 7
},
{
"test1": 383,
"test2": 100
},
{
"test1": 48,
"test2": 8
},
{
"test1": 383,
"test2": 100
},
{
"test1": 48,
"test2": 9
},
{
"test1": 383,
"test2": 100
},
{
"test1": 48,
"test2": 10
}
]
}
}
}';
$full = json_decode($full_json,true);
$test2range = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
$values=array_keys(array_column($full['1stelement']['2ndelement']['elements'], 'test2'),$test2range ,true);
// $values=array_keys(array_column($full['1stelement']['2ndelement']['elements'], 'test2'),5 ,true); // returns result
var_dump($values);
exit;
I want to get array_keys return values to process further.
Without array_keys function, we can get the values using foreach loop which is not advisable.
As per array_keys definition, search value parameter can be of mixed type, So we can give array of values.
When I tried that, result always give as an empty array which is not an expected result.
Can anyone explain how to accomplish this?
array_keys()supports only single values like thisprint_r(array_keys($a,"10",true));