I am trying to get some specific data from a csv file. Here is the link of the file:
Here is my code:
<?php
$row = 1;
$mycsvfile = array(); //define the main array.
$new_array = array();
if (($handle = fopen("php-files-task.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if($data['product_type'] == 'simple' && $data['price'] < 10){
$new_array = array_push($new_array, $data);
}
}
fclose($handle);
$fp = ['sku', 'product_type', 'name', 'price'];
foreach ($new_array as $key => $value) {
fputcsv($fp, $value);
}
}
?>
When I execute the code I get undefined index: ‘product type’. Also I am wondering how to put the result of $value in a new file called , results.csv". Thanks in advance