Convert String To Array In PHP

Thanks for reading my article first. Convert String To Array In PHP We are going to learn more about this in this article. Let’s go into the article

A string is used to store characters in a sequence and represent it as a single entity with a single data type.

Thus, data storage is flexible, making it easy to work with, whereas Array stores data as a particular entity and the data storage is fixed.

This is a syntax to do a task in the below program.

array str_split($org_string, $splitting_length)
Convert String To Array In PHP

Convert String to Array in PHP

We can see the example program to do a task in the below program. Let’s see how it works?

<?php
// PHP program to display the working of str_split()

$string = "Code";

// Since second argument is not passed,
// string is split into substrings of size 1.
print_r(str_split($string));

$string = "CodingDiksha";

// Splits string into substrings of size 3
// and returns array of substrings.
print_r(str_split($string, 3))
?>

Output

Array
(
    [0] => C
    [1] => o
    [2] => d
    [3] => e

)
Array
(
    [0] => Cod
    [1] => ing
    [2] => Dik
    [3] => sha
)

Read Also: PHP Arithmetic Operators

Final Thoughts

Convert String To Array In PHP We hope this article solves all your doubts. If in doubt let me know.

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment