Explode function using PHP

author details
AdiPie
4th Aug 2020
1 min read
Image
explode php

The explode() work breaks a string into a array. 

Note: The "separator" parameter can't be an unfilled string.

Note: This function is binary-safe.

Syntax: explode(separator,string,limit)

 

Technical Details

Return Value: Returns an array of strings

PHP Version: 4+

Changelog: The limit parameter was included PHP 4.0.1, and support for negative limits were included PHP 5.1.0

<?php
  $str = 'one,two,three,four';

  // zero limit
  print_r(explode( ' , ' ,$str,0));    //Array ( [0] => one,two,three,four )
  print "<br>";

  // positive limit
  print_r(explode( ' , ' ,$str,2));    //Array ( [0] => one [1] => two,three,four )
  print "<br>";

  // negative limit 
  print_r(explode( ' , ' ,$str,-1));   //Array ( [0] => one [1] => two [2] => three )
?>