use this function, it works well...
// recursively reduces deep arrays to single-dimensional arrays
// $preserve_keys: (0=>never, 1=>strings, 2=>always)
function array_flatten($array, $preserve_keys = 1, &$return = array()) {
foreach ($array as $key => $child) {
if (is_array($child)) {
$return =& array_flatten($child, $preserve_keys, $return);
} elseif ($preserve_keys + is_string($key) > 1) {
$return[$key] = $child;
} else {
$return[] = $child;
}
}
return $return;
}
----- Original Message -----
From: samuel darko
To: [email protected]
Sent: Tuesday, June 16, 2009 1:16 AM
Subject: array extraction
Hi guys:
i need help trimming down this:
Array( [0] => Array ( [0] => Array ( [Amount] => 72.64
) ))
TO this:
Array ( [Amount] => 72.64 )I tried the ff code but to no
avail:function afterFind($results, $primary=false) { if($primary ==
true) {
if(Set::check($results, '0.0')) {
$fieldName = key($results[0][0]); foreach($results as
$key=>$value) { $results[$key][$this->alias][$fieldName]
= $value[0][$fieldName];
unset($results[$key][0]); }
} } return $results; }
Thanks, in advance, for your help
-sam
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---