How to convert a sting into an array using php

How you can convert a string into an array using PHP language

PHP language

PHP is also known as a hypertext programming language. You can convert a string of characters into an array using the PHP "explode" function. Many of the programmers who started their career in the software field always stuck at this point of the program where the problem can solve by converting the string into an array. As a beginner, I also face the same issue as to how I can convert a string into an array.

Explode function:-  explode('delimiter','srting');

PHP Code

<?php 

$a="MY Name is Example";
explode(' ',$a);
foreach($a as $row){
echo $row;
}

?>

Also, You can do the reverse of this operation by converting the array into a string by the "implode" function.

Implode function:- implode('delimiter','array');

PHP Code

<?php 

$a = array('My','name','is','example');
echo implode(" ",$a);

?>

*

Post a Comment (0)
Previous Post Next Post