note 81989 added to function.array-walk
| From: | stroybomic at osu1 dot php dot net | Date: | Sat, 22 Mar 2008 23:24:21 +0000 |
| Subject: | note 81989 added to function.array-walk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137329@lists.php.net to get a copy of this message | ||
hioctiane at hioctiane dot de and ibolmo
<?php
class walker
{
public function walk(&$str_or_arr, $method, $string_or_object = NULL)
{
if ( is_array($string_or_object) )
{
$this->an_array(&$str_or_arr, $method, $string_or_object);
}
elseif ( is_string($string_or_object) )
{
$this->a_string(&$str_or_arr, $method, $string_or_object);
}
else
{
return false;
}
}
private function an_array(&$array, $method, $object = NULL)
{
//when argument object is given
if ( isset($object) )
{
//check if it is object
if (!is_object($object))
{
return false;
}
//check if _object_ has method
if ( !array_search( strtolower($method), get_class_methods( get_class($object) ) ) ) )
{
return false;
}
}
else
{
//check if _this_ class has method
if ( !array_search( strtolower($method), get_class_methods( get_class($this) ) ) )
{
return false;
}
}
foreach ($array as $key => $value)
{
//$value is array
if( is_array($value) )
{
//recursiv call of walk_multi_array
$result[$key] = $this->walk_multi_array(&$value, $method, $object);
}
//$value is value
else
{
if (is_object($object))
{
$result[$key] = $object->$method($value);
}
else
{
$result[$key] = $this->$method($value);
}
}
}
return $result;
}
private function a_string(&$string, $funcname, $userdata = NULL)
{
for($i = 0; $i < strlen($string); $i++)
{
# NOTE: PHP's dereference sucks, we have to do this.
$hack = $string{$i};
call_user_func($funcname, &$hack, $i, $userdata);
$string{$i} = $hack;
}
}
}
?>
----
Server IP: 212.124.37.9
Probable Submitter: 89.244.111.178
----
Manual Page -- http://www.php.net/manual/en/function.array-walk.php
Edit -- https://master.php.net/note/edit/81989
Del: integrated -- https://master.php.net/note/delete/81989/integrated
Del: useless -- https://master.php.net/note/delete/81989/useless
Del: bad code -- https://master.php.net/note/delete/81989/bad+code
Del: spam -- https://master.php.net/note/delete/81989/spam
Del: non-english -- https://master.php.net/note/delete/81989/non-english
Del: in docs -- https://master.php.net/note/delete/81989/in+docs
Del: other reasons-- https://master.php.net/note/delete/81989
Reject -- https://master.php.net/note/reject/81989
Search -- https://master.php.net/manage/user-notes.php