Have this array (as JSON):
{
"token_name": "C_ROOT",
"token_group": "C_BLOCK",
"group": true,
"body": [
[
{
"token_name_org": "T_VARIABLE",
"token": 320,
"value": "sort",
"line": 2,
"token_group": "VARIABLES",
"token_name": "C_VARIABLE"
},
{
"token_name_org": "C_ASSIGNMENT_EQUAL",
"line": 2,
"value": "=",
"token": "VALUE",
"token_group": "ASSIGNMENTS"
},
{
"token_name_org": "T_VARIABLE",
"token": 320,
"value": "_GET",
"line": 2,
"token_group": "VARIABLES",
"token_name": "C_VARIABLE",
"args": [
[
{
"token_name_org": "T_CONSTANT_ENCAPSED_STRING",
"token": 323,
"value": "sort",
"line": 2,
"token_group": "STRINGS",
"token_name": "C_STRING"
}
]
]
}
]
]
}
Wrote this code to search for key "value" being "sort".
public function search_var($array,$var)
{
foreach($array as $key=>$value)
{
if(is_array($value))
{
$this->search_var($value,$var);
}else{
if(isset($array["value"]) && $array["value"] == $var)
{
print $value."\n";
}
}
}
}
print_r($scanner->search_var($map,"sort"));
Don't know how can I reference in my code the siblings and childs? I.e
Now the output is:
T_VARIABLE
320
sort
2
VARIABLES
C_VARIABLE
How can I make it that I see as output only:
/sort/=/_GET/sort
Each value between "/" is a key "value" in sibling or child (last case)
Thanks,
/sort/=/_GET/sortwhen you only search for the one array havingvalue='sort'?/sort/=/_GET/sort). How should the function work if multiple paths are possible? For example, if the content ofbodyis duplicated and the values associated with thevaluekey are modified?