|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests |
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 15:00:02 2025 UTC |
Description: ------------ While preg_replace and str_replace can both apply changes to arrays of strings, strtr can only be passed one string at a time for translation; it can only be called as strtr(string, string, string) or strtr(string, array). This suggestion/request is for strtr to be support being called as, for example, strtr(array, string1$, string2$) (which would be effectively equivalent to array_map(function($w)use($string1, $string2) { return strtr($w, $string1, $string2); }, $array)). This would bring it into closer line with the other "string-search-and-replace" functions. Test script: --------------- $words = ['this', 'is', 'a', 'bunch', 'of', 'words', 'with', 'no', 'rhythm']; $translated = strtr($words, 'aeiou', 'AEIOU'); print_r($translated); Expected result: ---------------- Array ( [0] => thIs [1] => Is [2] => A [3] => bUnch [4] => Of [5] => wOrds [6] => wIth [7] => nO [8] => rhythm ) Actual result: -------------- A warning about a parameter 1 being an array instead of the expected string.