What are the potential pitfalls of using implode() with non-array data?

When using implode() with non-array data, the function will trigger a warning and return NULL, as it expects an array as its first parameter. To solve this issue, you can simply check if the data is an array before using implode(). If the data is not an array, you can convert it to an array before passing it to implode().

$data = "hello world";

if(is_array($data)){
  $result = implode(", ", $data);
} else {
  $result = implode(", ", (array)$data);
}

echo $result;