3v4l.org

run code in 300+ PHP versions simultaneously
<?php function fromCamelCaseToUnderscores($str) { $str[0] = strtolower($str[0]); // Just in case first character is uppercase. $str = str_replace('ID', 'Id', $str); // Hack for the way CATS defies camelCase convention return preg_replace_callback('/([A-Z])/', function($char) { return '_' . strtolower($char[1]); }, $str); } var_dump(fromCamelCaseToUnderscores(null));

preferences:
39.56 ms | 402 KiB | 5 Q