The explode Function
The explode
function splits a string into
an array by a specified delimiter.
Syntax
explode(string $separator, string $string, int $limit = PHP_INT_MAX): array
Example
Let's split the parts of a date into an array, using a hyphen as the delimiter:
<?php
$date = '2025-12-31';
$arr = explode('-', $date);
var_dump($arr);
?>
Code execution result:
['2025', '12', '31']
Example . Application
Let's say we have a date in the format '2025-12-31'
.
Let's convert it into a date in the format '31.12.2025'
.
To do this, we will split it into an array using explode
and form a new string in the format we need:
<?php
$date = '2025-12-31';
$arr = explode('-', $date);
echo $arr[2] . '.' . $arr[1] . '.' . $arr[0];
?>
Code execution result:
'31.12.2025'