<?php function findInArray($query, $data) { foreach ($query as $key) { if (!array_key_exists($key, $data)) { // The key was not found, set data to null and abort $data = null; break; } // Set data to the next level $data =& $data[$key]; } return $data; } $response = [ 'client1' => [ 'dog' => [ 'Jack' => 'Some value', 'Jack1' => 'Some value1', 'Jack2' => [ 'name' => 'Yes!', 'working' => [ 0 => 'Nope...', 1 => 'Seems like it!' ], ], ], ], 'client2' => [ 'cat' => [ 'Stacy' => 'Some other value', ], ], ]; $query = ['dog', 'Jack2', 'working', 1]; var_dump(findInArray($query, $response['client1']));
You have javascript disabled. You will not be able to edit any code.