Function explode
Function explode 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 date parts into an array, using hyphen as the delimiter:
<?php
$date = '2025-12-31';
$arr = explode('-', $date);
var_dump($arr);
?>
Code execution result:
['2025', '12', '31']
Example . Application
Given a date in the format '2025-12-31'.
Let's convert it to a date in the format '31.12.2025'.
To do this, 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'