ItSolutionStuff.com

PHP explode() Function Example Tutorial

By Hardik Savani • May 14, 2024
PHP

This article will provide example of php explode function. I’m going to show you about php explode string to array. it's simple example of php split string to array using explode. This article will give you simple example of explode function in php example.

The PHP explode() function breaks a string into an array. explode() takes a three argument separator, string and limit. limit is a optional.

Let's see below syntax and example:

Syntax:

explode(separator,string,limit)

Example 1:

index.php

<?php

$myString = "Hi, I am ItSolutionStuff.com";

$array = explode(' ', $myString);

print_r($array);

Output:

Array

(

[0] => Hi,

[1] => I

[2] => am

[3] => ItSolutionStuff.com

)

Example 2:

index.php

<?php

$myString = "Rajkot,Surat,Bhavnagar,Baroda";

$array = explode(',', $myString, 3);

print_r($array);

Output:

Array

(

[0] => Rajkot

[1] => Surat

[2] => Bhavnagar

)

I hope it can help you...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

šŸ“ŗ Subscribe on YouTube

We Are Recommending You

ā˜…

PHP Explode Every Character into Array Example

Read Now →
ā˜…

PHP Remove Element from Array by Value Example

Read Now →
ā˜…

How to Remove Last Element from Array in PHP?

Read Now →
ā˜…

PHP Multidimensional Array Search By Value Example

Read Now →
ā˜…

How to Remove undefined Value from Array in JQuery?

Read Now →
ā˜…

How to Get Maximum Key Value of Array in PHP?

Read Now →
ā˜…

How to Remove Empty Values from Array in PHP?

Read Now →
ā˜…

How to Add Prefix in Each Key of PHP Array?

Read Now →
ā˜…

How to Get Minimum Key Value of Array in PHP?

Read Now →
ā˜…

How to Remove Null Values from Array in PHP?

Read Now →