implode(): Invalid arguments passed – How to fix it

Warning: implode(): Invalid arguments passed” is one of the most popular warnings in PHP. It often shows when we are trying to use something else than a valid array as our second argument.

To fix it, make sure it’s a valid array.

Working example:


$array = ['element1', 'element2'];
$result = implode(" separator ", $array);

echo $result;


Output: element1 separator element2

Example 2:


$pets = ['dog', 'cat', 'turtle'];
echo implode(', ', $pets);


Output: dog, cat, turtle