For one of my php code, i want the json array as following from remote csv file in php.
The remote csv file: www.xyz.com/dir/records.csv
NAME Age ID
Jhon 45 101
Bhil 42 102
Tone 41 103
I want a function which converts this CSV file to a JSON array
Something Like this:
$json = '{"records":
[
{"Name":"Jhon", "Age":"45", "id":"101"},
{"Name":"Bhil", "Age":"42", "id":"102"},
{"Name":"Tone", "Age":"41", "id":"103"},
]
}';
Kindly guide me, how to incopporate the above csv file to get the above json array for the follwoing php code.
$myjson = json_decode($json, true);
foreach ( $myjson['records'] as $row ) {
if ($row['id'] =='101') {
foreach ( $row as $field => $value ) {
// do the work here
}
}
}