CKTIS / PHP
explode()
Split at exact occurrences of a nonempty separator, retaining empty fields.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
explode(string $separator, string $string, int $limit = PHP_INT_MAX): arraySplit at exact occurrences of a nonempty separator, retaining empty fields. A positive limit leaves the unsplit remainder in the last field, zero behaves like one, and a negative limit drops trailing fields. An empty separator raises ValueError in PHP 8.
Signature
explode(string $separator, string $string, int $limit = PHP_INT_MAX): array
Example output
[["a","","b",""],["a","b,c"],["a","b"],["a,b"]]
Examples
<?php
echo json_encode([explode(",","a,,b,"),explode(",","a,b,c",2),explode(",","a,b,c",-1),explode(",","a,b",0)]);
Result
[["a","","b",""],["a","b,c"],["a","b"],["a,b"]]