What are the best practices for preserving zero values when encoding arrays to JSON in PHP?

When encoding arrays to JSON in PHP, zero values can sometimes be lost or converted to null if not handled properly. To preserve zero values, one solution is to use the JSON_NUMERIC_CHECK option when encoding the array to JSON. This option ensures that numerical strings are converted to actual numbers in the JSON output.

$data = array(0, 1, 2, "0", "1", "2");
$json = json_encode($data, JSON_NUMERIC_CHECK);
echo $json;