The split()
and explode()
are two main string function in php. If you are working in php, You must have used these php function in your application. You have also faced some question in interviews regarding difference between php split and explode string function.
In this post, I will let you know what are the differences between Split() and Explode() php function with example.
The split()
function is use to splits the string into an array using a regular expression.The split method returns an array of string data. PHP split() function takes three arguments, first parameter is pattern regular expression which is case sensitive, second is input string and third one is for limit: If the limit is set, the returned array will contain a maximum of limit elements with the last element containing the whole rest of string.
You can read more from Implode And Explode In PHP 7 tutorial.
split(":", "this:is:a:string"); //returns an array that contains this, is, a, string.
Array( [0] => this, [1] => is, [2] => a, [3] => string )
The php explode()
function splits the string using delimiter and returns an array. PHP explode function takes three argument, first one takes delimiter as a argument, second one is target string and third one is limit : If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string.
The below example is used to explode the string using delimiter, The delimiter is this
string. Passing first one argument as a delimiter and second one is source string.
explode ("this", "this is a string"); //returns an array that contains array "is a string"
array([0] => "is a string")
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More