Contact me See Resume

Sting to array conversion using explode function -

Sting to array conversion using explode function

Catagory : PHP and mySQLi Posted : November, 10, 2018

In this tutorial we will discuss about PHP default function explode(). We can  easily make sting to array conversion using explode function.


Returns array from a string;


The Explode function takes three parameter :

  1. delimiter  // the point from where string separated.
  2. string       // from which it will create array.
  3. limit         // describe the the length of array.

The third parameter is optional.

Positive Limit

Limit accepts both positive and negative values. The positive value is define the length of array and if the positive value is less than from the length of the total elements of array it will keep rest elements in last elements.

Negative Limit

Negative limit ignore the last elements as per the negative value.

Zero Limit

Keep whole string into a single element.

Exp :

$str1 = "Jack is good boy. And he an one of best student.";
echo "<pre>";
print_r(explode(".",$str, -1));

Result :

[0] => PHP is a programming language
[1] => PHP is used for Web programming

Leave a Reply

You have to agree to the comment policy.