How can JSON encoding impact the formatting of array data in PHP?

When encoding array data to JSON in PHP, the default behavior can sometimes lead to numerical arrays being encoded as objects instead of arrays. To ensure that numerical arrays are encoded correctly as arrays in JSON, you can use the JSON_FORCE_OBJECT flag in the json_encode function. This flag will force all arrays to be encoded as objects.

$data = [1, 2, 3];
$json = json_encode($data, JSON_FORCE_OBJECT);
echo $json;