php array explode


 

php array explode

This section demonstrates the use of explode function in php

This section demonstrates the use of explode function in php

  • Explode function divides the given string into an array of strings
  • It uses the delimiter such as comma tab pipe space and semicolon


Example of PHP Array Explode
<?php
    $animal
="dog,cat,rat";
    echo
$animal;
    echo
"<br>size is ".sizeof($animal);
    $animal1
=explode(",",$animal);
    echo
"<br>after explode";

    foreach
($animal1 as $a)  {
     echo
"<br> ".$a;
    }
    echo
"<br>size is ".sizeof($animal1);
?>

Output

dog,cat,rat
size is 1
after explode
dog
cat
rat
size is 3

Ads