fork download
  1. <?php
  2. function arrayKeyPath ($searchFor, $arr, $keys=array())
  3. {
  4. if(!empty($arr) && is_array($arr)) {
  5. if(isset($arr[$searchFor])) {
  6. print_R($keys); // <<<<<<< NOTE
  7. return $keys;
  8. }
  9. foreach($arr as $pKey => $a) {
  10. if(is_array($a)) {
  11. $keys[] = $pKey;
  12. arrayKeyPath($searchFor, $a, $keys);
  13. }
  14. }
  15. }
  16. }
  17.  
  18. $user['results'][0] = array (
  19. 'userId' => '1',
  20. 'firstName' => 'John',
  21. 'lastName' => 'Doe',
  22. 'options' =>
  23. 'showNews' => 'on',
  24. 'newOptions' => array(
  25. 'option1'=> 1,
  26. 'option2'=> 2,
  27. 'option3'=> 3
  28. ),
  29. 'connectWithTimeFrame1' => '30',
  30. 'defaultMessageTemplate' => '12',
  31. 'connectWithTimeFrame' => 90,
  32. ),
  33. );
  34.  
  35.  
  36.  
  37. $exists = arrayKeyPath('option1', $user['results'][0]);
  38. var_dump($exists);
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
Array
(
    [0] => options
    [1] => newOptions
)
NULL