Re: [PHP4BETA] suggestion for new function str_change(string str,array transtable [,bool reverse])
| From: | Andi Gutmans | Date: | Sat, 20 Nov 1999 14:35:06 +0000 |
| Subject: | Re: [PHP4BETA] suggestion for new function str_change(string str,array transtable [,bool reverse]) | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-6581@lists.php.net to get a copy of this message | ||
At 03:04 PM 11/20/99 +0100, Thies C. Arntzen wrote:
On Sat, 20 Nov 1999, Rasmus Lerdorf wrote:have you thought of doing this in an efficient way or are you just going to call strstr() X times where X is the amount of key/value's in the array? I guess making it more efficient than that would require building a finite state automata which is a bitch. By the way, I wouldn't have a rule for collisions. You'll just make things complicated and it won't be very useful in any case. Andi --- Andi Gutmans <andi@zend.com> http://www.zend.com/i think extending strtr() is cooler that creating a new function, but - how do we pass the "do-the-reverse" flag to the function? i think we could instead create an array_switch_key_and_value() function (with a nicer name) so that: $trans = array("ue" => "ü", "oe" => "ö"); $str = "oeluebung"; $str = strtr($str,$trans); // now $str is "ölübung"; $trans = array_switch_key_and_value($trans); // now $trans =array("ü" => "ue", "ö" => "oe")$str = strtr($str,$trans); // now $str is "oeluebung" again.Yes, I like this. How about just naming it flip() ? Or perhaps array_flip()? There are all sorts of uses for this function on its own. We'd have to figure out what to do in the case of: $a[0]="abc"; $a[1]="abc"; Does $a[abc] become 0 or 1 after the flip? Or perhaps it becomes 2 on the theory that it might be cool to count the number of instances of a particular index. I guess the behaviour could be chosen with an argument. The choices being: - Select lowest value for multiply occurring indices - Select highest value for multiply occurring indices - Count number of occurences of index and make that the value for that index i like it, not sure about my girlfriend (it's weekend;-) i'l do the strtr() part now - rest to follow!