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

str_split() function in php

Last Updated by Pooja Chikara

0 2249

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:




Best WordPress Hosting


Share:

SSL for business, from $12.88


Leave a Reply


Comments
    Waiting for your comments

Coding Tag WhatsApp Chat
Coding Tag WhatsApp Chat