How to Convert String into Array in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP Multidimensional Array Search By Value Example
- PHP Check If Array Is Multidimensional or Not
- How to Remove Multiple Keys from PHP Array?
- How to Remove Specific Element by Value from Array in PHP?
- How to Remove undefined Value from Array in JQuery?
- How to Get Maximum Key Value of Array in PHP?
- How to Remove Empty Values from Array in PHP?
- How to Add Prefix in Each Key of PHP Array?
- How to Get Minimum Key Value of Array in PHP?
- How to Remove Null Values from Array in PHP?
- How to Merge Two Array with Same Keys without Loop in PHP?