str_split() function in PHP || PHP str_split() function
×


str_split() function in php

0 510

str_split() function of PHP is used to splits a string into an array. It is an inbuilt function of PHP.

Also, read PHP explode() function.

Syntax:

str_split($string,$length);

here,

  • $string is a PHP string that is converted into an array by this function. It is required.
  • $length specifies the length of each array element. It is optional. 1 is the default value of this parameter.

Example:

<?php
$str="Welcome";
$str_arr=str_split($str);
echo "<pre>";
print_r($str_arr);
?>

Output:


Example 2:

<?php
$str="Welcome";
$str_arr=str_split($str,2);
echo "<pre>";
print_r($str_arr);
?>

Output:




Share:


Leave a Reply


Comments
    Waiting for your comments