I have this code, basically take some lines and put in a array in groups of 4
Originally the data comes in this format:
line1
line2
line3
line4
line5
line6
line7
line8
and with this code i pass the lines to array:
$addresses = [];
foreach (preg_split("/((?
)|(
?))/", $nodes) as $line) {
$temp[] = trim($line);
if(count($temp) == 4){
array_push($addresses,[
'ADDRESS' => $temp[0],
'STREET_NAME' => $temp[1],
'TOWN_NAME' => $temp[2],
'POST_CODE' => $temp[3]
]);
$temp = [];
}
}
var_dump(json_encode($addresses,JSON_PRETTY_PRINT));
But the result its not what i want... :
{
"1": {
"ADDRESS": "10",
"STREET_NAME": "TRIQ ID-DAR TA` PULTU",
"TOWN_NAME": "BIRZEBBUGA",
"POST_CODE": "BBG 1810"
},
"2": {
"ADDRESS": "12",
"STREET_NAME": "TRIQ ID-DAR TA` PULTU",
"TOWN_NAME": "BIRZEBBUGA",
"POST_CODE": "BBG 1810"
}
}
And i dont want the index...
i need something like this:
[
{
"ADDRESS": "10",
"STREET_NAME": "TRIQ ID-DAR TA` PULTU",
"TOWN_NAME": "BIRZEBBUGA",
"POST_CODE": "BBG 1810"
},
{
"ADDRESS": "12",
"STREET_NAME": "TRIQ ID-DAR TA` PULTU",
"TOWN_NAME": "BIRZEBBUGA",
"POST_CODE": "BBG 1810"
}
]
Any idea about the mistake???