Re: is there a builtin php function for this ?
| From: | Chris Lee | Date: | Tue, 09 Jan 2001 20:49:14 +0000 |
| Subject: | Re: is there a builtin php function for this ? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-33538@lists.php.net to get a copy of this message | ||
array_walk() doesnt seem to fit my code, unless Im not suing it right... I
cant see how I would use it. array_walk() will execute a function on every
element of my array ie.
<?
function dsp($val, $pos)
{
echo "$pos : $val<br>\n";
}
$test[0] = "hello";
$test[1] = "hi";
$test[2] = "oi";
array_walk($test, 'dsp');
?>
this will dsiplay all the keys and values. how can I add them?
the only way I could see your method of workings is imensly complex
<?
class add
{
var $value;
function dsp($val, $pos)
{
@$this->value += $val;
}
}
$test[0] = 3;
$test[1] = 2;
$test[2] = 5;
$class = new class;
array_walk($test, 'class->dsp');
echo $class->value * $tax;
?>
I am obviously missing something here, I would apreciate you clarifying me
:) such a simple function would be handy.
Chris Lee
Mediawaveonline.com
""MR"" <ivansanchez@wanadoo.es> wrote in message
news:93fsm6$3gf$1@toye.p.sourceforge.net...
> "Chris Lee" ...
> >
> > is there a built in function to replace add_all, I would like to have a
> > add_all, multiply_all, divide_all, etc etc. a php function would just be
> > nicer...
>
> Have a look to array_walk() - it applies a function to every element of an
array.
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>