A "callback" is when you execute a function, and you provide to it a name of
*another* function, which it will call on some data in the middle of its
task.

It's a very handy way to provide extreme flexibility in functional
languages.

For example:

function my_array_walk($array, $function){
    while (list($k, $v) = each($array)){
        # Here's the magic that implements a 'callback'
        $function($k, $v);
    }
}

function your_echo($key, $value){
    echo "$key $value<BR>\n";
}

$foo = array('a'=>1, 'b'=>2, 'c'=>3);

my_array_walk($foo, 'your_echo');

This rather silly example will "walk" the array and call 'your_echo' on each
key/value pair.

Dunno exactly how preg_ uses it though...

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
----- Original Message -----
From: Arash Dejkam <[EMAIL PROTECTED]>
Newsgroups: php.general
To: <[EMAIL PROTECTED]>
Sent: Saturday, September 08, 2001 7:35 PM
Subject: preg_replace_callback()


> Hi,
>
> What is a callback in preg_replace_callback(...) ?
> how can I use it ? can anybody give me an example ?
>
> Thanks,
> Arash
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to