I'm trying to get data from .CSV , sort it in array (using PHP), select specific values in it, create an new array fron this selection and encode it to a json object usable with ajax.
With this code, I'm able to get almost what I want.
$CSV_url = '../fichier-csv/commande.csv'; // CSV file
$csv["data"] = array_map('str_getcsv', file($CSV_url)); // to PHP array
array_shift($csv["data"]); // remove first line (headers)
$jsonData = json_encode($csv); // to Json
The CSV file contains about 16 categories of data per line, but i only need 4 of them in my final json.
I'm stuck with this result . If I print before json_encode ($csv), I get a nice array, but I've trouble to select the wanted data and making new array with it (which is the way I think this should be done, but i'm a beginner, maybe there is a more simple way to do it).
Outputed Json should also be sorted in ascending order of the [0] value of each arrays. Here is the beginnig of the arrays I get (378 of them to proccess):
Array (
[data] => Array
(
[0] => Array
(
[0] => 100120148
[1] => 1.0000
[2] => 7.4200
[3] => 2.4700
[4] => 4.9100
[5] => 0.0000
[6] => 14.8000
[7] => 0.3000
[8] => marie
[9] => jardin
[10] => 40 rue mazé
[11] => 87400
[12] => 066825197
[13] => [email protected]
[14] => 1
[15] => [email protected]
)
[1] => Array
(
[0] => 100120162
[1] => 1.0000
[2] => 45.7500
[3] => 10.8000
[4] => 8.2500
[5] => 0.0000
[6] => 64.8000
[7] => 2.0000
[8] => __
[9] => Lucien fizon
[10] => 56 impasse pazarre
[11] => 25000
[12] => 0649851473
[13] => [email protected]
[14] => 4
[15] => [email protected]
)
How do I get values 0, 8, 9 and 12 of each sub-array and create a new array with it, so I can encode this desired array to Json ?
Thanks.