How to use explode() Function In PHP

The explode() function is useful when dealing with delimited strings. It splits a string into an array based on a specified delimiter and assigns the values to variables.

PHP




<?php
  
$str = "Geeks, Noida, +91-9876543210";
list($name, $address, $mobile) = explode(',', $str);
  
echo "$name, $address, $mobile";
  
?>


Output

Geeks,  Noida,  +91-9876543210

How to Assign Multiple Variables in One Line in PHP ?

In PHP, assigning multiple variables in one line can be a handy and efficient way to streamline your code. This technique not only makes your code more concise but also improves readability. There are several approaches to achieve this, each with its own syntax and use cases.

Table of Content

  • Using Multiple Assignment
  • Using list() Function
  • Using explode() Function
  • Using Short Array Syntax

Similar Reads

Using Multiple Assignment

PHP allows multiple variables to be assigned the same value in a single line....

Using list() Function

...

Using explode() Function

The list() function is a versatile way to assign multiple variables at once. It allows you to assign values from an array to individual variables in a single line....

Using Short Array Syntax

...