PHP str_split() Function


The str_split() function is used to converted a string into an array.The split length is specified.

Syntax
str_split(string,length)
Parameters
  • string - (required) Specifies the string to split.
  • length - (optional) Specifies the length of each array element.
Example
<?php
    print_r(str_split("Welcome"));
?>

Output

Array ( [0] => W [1] => e [2] => l [3] => c [4] => o [5] => m [6] => e )
Example
<?php
    print_r(str_split("Welcome",2));
?>

Output

Array ( [0] => We [1] => lc [2] => om [3] => e )

Prev Next