note 118829 added to function.array-keys
| From: | RobertC. | Date: | Fri, 12 Feb 2016 14:22:07 +0000 |
| Subject: | note 118829 added to function.array-keys | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204927@lists.php.net to get a copy of this message | ||
Keys from multi dimensional array to simple array
Want to traverse an multi dimensional array and get the keys back in a single dimensional array?
This will do the trick:
<?php
public function array_walk_keys($array, $parentKey = null, &$flattened_array = null)
{
if(!is_array($array))
return $array;
foreach( $array as $key => $val ) {
$flattenedKeysArray[] = $key;
if(is_array($val))
array_walk_keys($val, $key, $flattenedKeysArray);
}
return $flattenedKeysArray;
}
----
Server IP: 72.52.91.14
Probable Submitter: 80.57.113.89
----
Manual Page -- http://php.net/manual/en/function.array-keys.php
Edit -- https://master.php.net/note/edit/118829
Del: integrated -- https://master.php.net/note/delete/118829/integrated
Del: useless -- https://master.php.net/note/delete/118829/useless
Del: bad code -- https://master.php.net/note/delete/118829/bad+code
Del: spam -- https://master.php.net/note/delete/118829/spam
Del: non-english -- https://master.php.net/note/delete/118829/non-english
Del: in docs -- https://master.php.net/note/delete/118829/in+docs
Del: other reasons-- https://master.php.net/note/delete/118829
Reject -- https://master.php.net/note/reject/118829
Search -- https://master.php.net/manage/user-notes.php