I have created this small script in order to parse a cvs file and then pass it on to mysql. I need to do quite some editing to it but I just started with editing the format of the date according to the http://csv.thephpleague.com manual.
<?php
if (!ini_get("auto_detect_line_endings")) {
ini_set("auto_detect_line_endings", '1');
}
use League\Csv\Reader;
$reality = Reader::createFromPath('Workbook3.csv');
$planed = Reader::createFromPath('Workbook4.csv');
/*this function removes the "First name" "Second name" elements and
creates one that actually has the entier name in capital*/
$functionHRT = function ($row) {
$row['hrtData'] => DateTimeImmutable::createFromFormat($row['Contract Start'], 'd-m-Y'); /*this is line 18*/
}
$hrtData = $reality
// ->setOffset(7);
->fetchAssoc( , $functionHRT());
$hrtData[0]['Contract Start']->format('Y-m-d');
?>
When I try to run this I get an:
Parse error: parse error in /Users/nefeli/Code/ph/script.php on line 18
error code. I am not sure what the problem syntax error is. Any insight on this?
This line has a syntax error:
$reality->fetchAssoc( , $functionHRT());
According to the docs this is the method's signature:
fetchAssoc($offset_or_keys = 0, callable $callable = null)
So, if you want to pass the callback you have to specify also the first parameter to the function. You can use the default (0) and pass the callback as the second parameter.
Also remember that when you're passing the callback you don't have to call it (using the parentheses like you're doing) but you only need to specify the variable, as you've previously declared the lamba function and stored it in the $functionHRT
variable
So your call should be:
$reality->fetchAssoc( 0, $functionHRT );
Another error is in the statement:
$functionHRT = function ($row) {
$row['hrtData'] => DateTimeImmutable::createFromFormat($row['Contract Start'], 'd-m-Y'); /*this is line 18*/
}
You're using the wrong operator to assign a value to the array. It should be:
$functionHRT = function ($row) {
$row['hrtData'] = DateTimeImmutable::createFromFormat($row['Contract Start'], 'd-m-Y'); /*this is line 18*/
};
You need also to add a semicolon at the end of the callback's declaration