What are common pitfalls when using json_encode with arrays in PHP?

When using json_encode with arrays in PHP, a common pitfall is that associative arrays may not be encoded correctly. To ensure proper encoding, use the JSON_FORCE_OBJECT flag as the second parameter in the json_encode function. This will force the array to be encoded as an object in JSON format.

// Example of using json_encode with arrays in PHP
$data = array("name" => "John", "age" => 30);
$json = json_encode($data, JSON_FORCE_OBJECT);

echo $json;