Created
          February 5, 2018 15:33 
        
      - 
      
 - 
        
Save arvindsvt/b30334b9d9f38cb46cce9c6d95c4abb3 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| function multidimensional_array_search($search_value,$array) { | |
| $mached = array(); | |
| if(is_array($array) && count($array) > 0) { | |
| foreach($array as $key => $value) { | |
| if(is_array($value) && count($value) > 0) { | |
| multidimensional_array_search($search_value,$value); | |
| } else { | |
| return array_search($search_value,$array); exit; | |
| } | |
| } | |
| } | |
| } | |
| // useage | |
| echo multidimensional_array_search('test3',array('test','test1','test2','test3')); | |
| function recursiveArraySearch($haystack, $needle, $index = null) | |
| { | |
| $aIt = new RecursiveArrayIterator($haystack); | |
| $it = new RecursiveIteratorIterator($aIt); | |
| while($it->valid()) | |
| { | |
| if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($it->current() == $needle)) { | |
| return $aIt->key(); | |
| } | |
| $it->next(); | |
| } | |
| return false; | |
| } | |
| ?> | |
| Removing specific value Using array_diff() | |
| function remove_element($array,$value) { | |
| return array_diff($array, (is_array($value) ? $value : array($value))); | |
| } | |
| $myArray = array('php', 'laravel', '.net', 'java', 'c#', 'javascript'); | |
| $result = remove_element($myArray,'.net'); | |
| print_r($result); | |
| array_map | |
| function my_array_map($function, $arrary) | |
| { | |
| $result = array(); | |
| foreach ($arr as $key => $val) | |
| { | |
| $result[$key] = (is_array($val) ? my_array_map($function, $val) : $function($val)); | |
| } | |
| return $result; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment