note 80963 added to function.array-map
| From: | avartabedian at webservice dot com dot uy | Date: | Fri, 08 Feb 2008 13:39:36 +0000 |
| Subject: | note 80963 added to function.array-map | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135909@lists.php.net to get a copy of this message | ||
loaded67 at hotmail dot com, there is a little error in the add func params values.
Warning: Missing argument 2 for test::add(), called in /tmp/test.php on line 34 and defined in
/tmp/test.php on line 6
Array => <br/>
now it runs...
<?php
class test{
//private $container = array();
final public function add($key, $value=NULL){
/* params values fix */
$value = $value==NULL?$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);
?>
good luck!
----
Server IP: 69.147.83.197
Probable Submitter: 201.217.130.135
----
Manual Page -- http://www.php.net/manual/en/function.array-map.php
Edit -- https://master.php.net/note/edit/80963
Del: integrated -- https://master.php.net/note/delete/80963/integrated
Del: useless -- https://master.php.net/note/delete/80963/useless
Del: bad code -- https://master.php.net/note/delete/80963/bad+code
Del: spam -- https://master.php.net/note/delete/80963/spam
Del: non-english -- https://master.php.net/note/delete/80963/non-english
Del: in docs -- https://master.php.net/note/delete/80963/in+docs
Del: other reasons-- https://master.php.net/note/delete/80963
Reject -- https://master.php.net/note/reject/80963
Search -- https://master.php.net/manage/user-notes.php