Function explode

Function explode splits a string into an array by a specified delimiter.

Syntax

phpexplode(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<?php
  $date = '2025-12-31';
  $arr = explode('-', $date);
  
  var_dump($arr);
?>

Code execution result:

php['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<?php
  $date = '2025-12-31';
  $arr = explode('-', $date);
  
  echo $arr[2] . '.' . $arr[1] . '.' . $arr[0];
?>

Code execution result:

php'31.12.2025'

See Also

  • function implode,
    which joins array elements into a string
  • function str_split,
    which splits a string into an array by length