ItSolutionStuff.com

How to Convert String into Array in PHP?

By Hardik Savani • May 14, 2024
PHP

In this short tutorial we will cover an how to convert string into array in php. step by step explain how to convert string value into array in php. I would like to share with you php convert string to array by comma. you'll learn php convert string to array with delimiter. follow bellow step for how to create array from string in php.

We will use explode() to convert string to array in PHP. explode() provide ways to convert a string into an array using a delimiter. I will give you two examples that way you can understand how it works.

Let's see below example:

Example 1:

index.php

<?php

$myString = "Hi, I am ItSolutionStuff.com";

$array = explode(' ', $myString);

print_r($array);

Output:

Array

(

[0] => Hi,

[1] => I

[2] => am

[3] => ItSolutionStuff.com

)

Example 2:

index.php

<?php

$myString = "Rajkot,Surat,Bhavnagar,Baroda";

$array = explode(',', $myString);

print_r($array);

Output:

Array

(

[0] => Rajkot

[1] => Surat

[2] => Bhavnagar

[3] => Baroda

)

I hope it can help you...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

PHP Multidimensional Array Search By Value Example

Read Now →

PHP Check If Array Is Multidimensional or Not

Read Now →

How to Remove Multiple Keys from PHP Array?

Read Now →

How to Remove Specific Element by Value from Array in PHP?

Read Now →

How to Remove undefined Value from Array in JQuery?

Read Now →

How to Get Maximum Key Value of Array in PHP?

Read Now →

How to Remove Empty Values from Array in PHP?

Read Now →

How to Add Prefix in Each Key of PHP Array?

Read Now →

How to Get Minimum Key Value of Array in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →

How to Merge Two Array with Same Keys without Loop in PHP?

Read Now →