Advertisement
Guest User

Untitled

a guest
May 27th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. private function find($needle, $haystack) {
  2. foreach ($haystack as $name => $file) {
  3. if ($needle == $name) {
  4. return $file;
  5. } else if(is_array($file)) { //is folder
  6. return $this->find($needle, $file); //file is the new haystack
  7. }
  8. }
  9.  
  10. return "did not find";
  11. }
  12.  
  13. function recursiveFind(array $array, $needle)
  14. {
  15. $iterator = new RecursiveArrayIterator($array);
  16. $recursive = new RecursiveIteratorIterator(
  17. $iterator,
  18. RecursiveIteratorIterator::SELF_FIRST
  19. );
  20. foreach ($recursive as $key => $value) {
  21. if ($key === $needle) {
  22. return $value;
  23. }
  24. }
  25. }
  26.  
  27. function array_search_key( $needle_key, $array ) {
  28. foreach($array AS $key=>$value){
  29. if($key == $needle_key) return $value;
  30. if(is_array($value)){
  31. if( ($result = array_search_key($needle_key,$value)) !== false)
  32. return $result;
  33. }
  34. }
  35. return false;
  36. }
  37.  
  38. public function recursiveFind(array $array, $needle)
  39. {
  40. $iterator = new RecursiveArrayIterator($array);
  41. $recursive = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
  42. $aHitList = array();
  43. foreach ($recursive as $key => $value) {
  44. if ($key === $needle) {
  45. array_push($aHitList, $value);
  46. }
  47. }
  48. return $aHitList;
  49. }
  50.  
  51. array_walk_recursive(
  52. $arrayToFindKey,
  53. function($value, $key, $matchingKey){
  54. return (strcasecmp($key, $matchingKey) == 0)? true : false;
  55. }
  56. , 'matchingKeyValue'
  57. );
  58.  
  59. function recursiveFind(array $array, $needle) {
  60. $iterator = new RecursiveArrayIterator($array);
  61. $recursive = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
  62. $return = [];
  63. foreach ($recursive as $key => $value) {
  64. if ($key === $needle) {
  65. $return[] = $value;
  66. }
  67. }
  68. return $return;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement