note 104184 modified in function.array-values by thiago
| From: | thiago@php.net | Date: | Tue, 31 May 2011 03:40:29 +0000 |
| Subject: | note 104184 modified in function.array-values by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180106@lists.php.net to get a copy of this message | ||
<?php
/**
* Flattens an array, or returns FALSE on fail.
*/
function array_flatten($array) {
if (!is_array($array)) {
return FALSE;
}
$result = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$result = array_merge($result, array_flatten($value));
}
else {
$result[$key] = $value;
}
}
return $result;
}
?>
--was--
Sorry, I am using the below function in one of my Drupal modules called Adhan. Hence the wrong
function name. Here it is corrected.
<?php
/**
* Flattens an array, or returns FALSE on fail.
*/
function array_flatten($array) {
if (!is_array($array)) {
return FALSE;
}
$result = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$result = array_merge($result, adhan_flatten($value));
}
else {
$result[$key] = $value;
}
}
return $result;
}
?>
http://php.net/manual/en/function.array-values.php