@ 2019-02-11T22:26:00Z <?php
$array = '{"uuid":"8888888888888","templateUuid":"001","trashed":"N","createdAt":"2018-09-05T07:52:37Z","updatedAt":"2019-01-24T18:45:35Z","changerUuid":"HHHHHHHHHHHHHH","itemVersion":7,"vaultUuid":"VVVVVVVVVVVVVVVVV","details":{"fields":[{"designation":"username","name":"username","type":"T","value":"33333333333333333333333333"},{"designation":"password","name":"password","type":"P","value":"9999999999999999999999999"}],"notesPlain":"aa","sections":[{"fields":[{"k":"concealed","n":"fffffffffffffffff","t":"custom","v":"something"}],"name":"Section_acydazbajjhifgnahiej3wdrxi","title":""}]},"overview":{"URLs":[{"l":"website","u":"https://api.example.com/"}],"ainfo":"33453ff2e19203cacb35dac4b304f4d3e69020a8","pbe":0,"pgrng":false,"ps":100,"tags":[],"title":"EXAMPLE API KEY","url":"https://api.example.com/"}}';
//echo print_r(json_decode($array, true), true);
function findPath($array, $targetKey, $targetValue, $path = []) : ? string
{
if (!is_array($array)) {
$array = json_decode($array, true);
}
foreach ($array as $key => $value) {
if ($key === $targetKey && $value === $targetValue) {
$path[] = $key;
return implode('.', $path);
}
}
foreach ($array as $key => $value) {
if (is_array($value)) {
$path[] = $key;
if (($result = findPath($value, $targetKey, $targetValue, $path)) !== null) {
return $result;
} else {
array_pop($path);
}
}
}
return null;
}
echo print_r(findPath($array, 'url', 'https://api.example.com/'), true);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.4 , 8.3.6 overview.url Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
overview.url preferences:dark mode live preview
142.25 ms | 402 KiB | 156 Q