PHP 8.5 implode() Function With Example

The implode() function in PHP 8.5 works the same as in PHP 8.0+, with no new changes to its core behavior. It joins array elements into a single string using a separator.

Function Signature

implode(string $separator, array $array): string

Key Changes (PHP 8.0+)

→Legacy parameter order removed: You can no longer pass the array first and separator second. The separator must always come first .
→Strict type checking: Passing a non-array as the second argument now throws a TypeError instead of silently converting .

Example

<?php
$array = [ lastname , email , phone ];

// Standard usage with separator
echo implode(",", $array); 
// Output: lastname,email,phone

// Separator is optional (defaults to empty string)
echo implode([ a , b , c ]); 
// Output: abc

// Empty array returns empty string
echo implode( hello , []); 
// Output: (empty string)
?>

7 Views