- var_export: documentation ( source)
- json_encode: documentation ( source)
- range: documentation ( source)
<?php
$country_ids = range(1,5);
$result['fields'][0]['field_type'] = "countries";
foreach ($country_ids as $id) {
$result['fields'][0]['field_value'][] = ["country_id" => $id, "match_type" => "exact"];
}
var_export($result);
echo "\n---\n";
echo json_encode($result, JSON_PRETTY_PRINT); // this resembles your posted data