Re: [PHP4BETA] suggestion for new function str_change(string str,array transtable [,bool reverse])
| From: | Thies C. Arntzen | Date: | Sat, 20 Nov 1999 14:04:49 +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-6577@lists.php.net to get a copy of this message | ||
On Sat, 20 Nov 1999, Rasmus Lerdorf wrote:
> > 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!
tc
>
> -Rasmus
>
>
Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!"
Digital Collections Phone +49 40 235350 Fax +49 40 23535180
Hammerbrookstr. 93 20097 Hamburg / Germany