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.32, 8.0.0 - 8.0.24, 8.1.0 - 8.1.11
AAaaĄaśćŻŹ

preferences:
65.89 ms | 409 KiB | 5 Q