<?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
- Output for 5.6.38, 7.1.0 - 7.1.24, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.20, 8.3.0 - 8.3.8
- array (
'fields' =>
array (
0 =>
array (
'field_type' => 'countries',
'field_value' =>
array (
0 =>
array (
'country_id' => 1,
'match_type' => 'exact',
),
1 =>
array (
'country_id' => 2,
'match_type' => 'exact',
),
2 =>
array (
'country_id' => 3,
'match_type' => 'exact',
),
3 =>
array (
'country_id' => 4,
'match_type' => 'exact',
),
4 =>
array (
'country_id' => 5,
'match_type' => 'exact',
),
),
),
),
)
---
{
"fields": [
{
"field_type": "countries",
"field_value": [
{
"country_id": 1,
"match_type": "exact"
},
{
"country_id": 2,
"match_type": "exact"
},
{
"country_id": 3,
"match_type": "exact"
},
{
"country_id": 4,
"match_type": "exact"
},
{
"country_id": 5,
"match_type": "exact"
}
]
}
]
}
preferences:
180.69 ms | 406 KiB | 180 Q