3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'aaAAąAŚĆżź'; echo preg_replace_callback( '/(\p{Lu})|(\p{Ll})/u', function($m) { return $m[1] ? mb_strtolower($m[1]) : mb_strtoupper($m[2]); }, $string );
Output for 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
AAaaĄaśćŻŹ

preferences:
144.73 ms | 402 KiB | 151 Q