note 80958 added to function.array-map
| From: | loaded67 at hotmail dot com | Date: | Fri, 08 Feb 2008 10:59:23 +0000 |
| Subject: | note 80958 added to function.array-map | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135898@lists.php.net to get a copy of this message | ||
this function is really nice for recursion in php!!!
example in a class:
<?php
class test{
//private $container = array();
final public function add($key, $value){
/* recursion */
if(is_array($value)){
array_map(array($this, __FUNCTION__), array_keys($value), array_values($value));
}
/* procedural */
else{
echo $key.' => '.$value.'<br/>'.PHP_EOL;
// do stuff...
// if(!isset($this->container[$key])){
// $this->container[$key] = $value;
// }
//else{ // trigger_error() xor throw new Exception?
// echo 'allready exists!<br/>'.PHP_EOL;
//}
}
}
}
//
$array = array (
'one' => 'value1',
'two' => 'value2',
'three' => 'value3'
);
$t = new test;
$t->add($array);
?>
you could easiely do this without a class too offcourse!
used in php 5.2.5
----
Server IP: 83.137.20.135
Probable Submitter: 62.234.63.246
----
Manual Page -- http://www.php.net/manual/en/function.array-map.php
Edit -- https://master.php.net/note/edit/80958
Del: integrated -- https://master.php.net/note/delete/80958/integrated
Del: useless -- https://master.php.net/note/delete/80958/useless
Del: bad code -- https://master.php.net/note/delete/80958/bad+code
Del: spam -- https://master.php.net/note/delete/80958/spam
Del: non-english -- https://master.php.net/note/delete/80958/non-english
Del: in docs -- https://master.php.net/note/delete/80958/in+docs
Del: other reasons-- https://master.php.net/note/delete/80958
Reject -- https://master.php.net/note/reject/80958
Search -- https://master.php.net/manage/user-notes.php