What are potential pitfalls of using substring to list array elements in PHP?

When using substring to list array elements in PHP, a potential pitfall is that it may not work as expected if the array elements are not strings. To solve this issue, you can use the implode function to concatenate array elements into a string before using substring to extract a portion of the string.

// Example array with mixed data types
$array = [1, 'apple', true, 3.14, 'banana'];

// Convert array elements to string and concatenate them
$string = implode(',', $array);

// Use substring to extract a portion of the string
$substring = substr($string, 0, 10);

echo $substring; // Output: 1,apple,t