How to convert a string in to an array in php? (string to array php)

In certain situations, we may want to convert a string into an array. In php, we can convert a string into an array. (string to array PHP)

String to array PHP

PHP has a function explode and using explode function we can convert a string into an array.

<?php
$string="Apple Banana Orange Guava";
$fruitnames=explode(" ",$string);
echo $fruitnames;
?>

Output: Array

Note;

- Explode function takes two parameters. One is the 'separator' and second one is the string.
- In the above example, the string has spaces. So we have used to space as separator.

If the string contains commas, then we can use comma as separator.
How to convert a string in to an array in php? (string to array php) How to convert a string in to an array in php? (string to array php) Reviewed by Pixel Stream on December 09, 2019 Rating: 5

No comments:

Powered by Blogger.