PHP explode() Function

PHP explode() function is often used to split a string into an array by a specified string.

Syntax

array explode(delimiter,str,limit);

explode() Function Parameter

ParameterDescription
delimiter :Required parameter. The boundary string.
str :Required parameter. The input string.
limit :Required parameter. The number of array elements to be return.

  • If > 0 - Returns an array with mentioned limit elements.
  • If < 0 - Returns an array with mentioned limit - 1 elements.
  • 0 - Returns an array with one element

explode() Function Return Value

Return Value :Returns an string array splitted with delimiter.

explode() Function Example

<?php
$str = 'James|Scott|Manager|29|7428323323';

// Zero limit
echo explode('|',$str,0);

// Greater than 1 limit
echo explode('|',$str,2);

// Less than 1 limit 
echo explode('|',$str,-1);
?>