Re: preg_replace_callback()

From: Date: Sun, 09 Sep 2001 02:26:12 +0000
Subject: Re: preg_replace_callback()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-66584@lists.php.net to get a copy of this message
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 richard@zend.com address is an endangered species -- Use ceo@l-i-e.com 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 <arash@dejkam.f2s.com> Newsgroups: php.general To: <php-general@lists.php.net> 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 > >

« previous php.general (#66584) next »