Php

PHP return all keys from multidimensional array

/**
      * Function can return all the non numeric keys from a multidimensional array
      * @param type $array
      * @return type
      */
     public function getKeysFromArray($array)
     {
         $fields = $this->getKeys($array);
         foreach ($fields as $key => $value)
         {
             if (is_numeric($key))
             {
                 unset($fields[$key]);
             }
         }
         return $fields;
     }

/**  
* Get all the key from a multidimensional array in recursive mod  
* @param type $array  
* @return type  */ 
function getKeys($array) 
{     
$keys = [];     
foreach ($array as $key => $value)     
{         
$keys[$key] = $key;         
if (is_array($value))         
{             
$keys = array_merge($keys, $this->getKeys($value));         
}     
}     
return $keys; 
}

Similar Posts