Elastica\Util::toSnakeCase PHP Méthode

toSnakeCase() public static méthode

For Example HelloWorld to hello_world
public static toSnakeCase ( string $string ) : string
$string string CamelCase String to Convert
Résultat string SnakeCase string
    public static function toSnakeCase($string)
    {
        $string = preg_replace('/([A-Z])/', '_$1', $string);
        return strtolower(substr($string, 1));
    }

Usage Example

 public function testToSnakeCase()
 {
     $string = 'HelloWorld';
     $this->assertEquals('hello_world', Util::toSnakeCase($string));
     $string = 'HowAreYouToday';
     $this->assertEquals('how_are_you_today', Util::toSnakeCase($string));
 }