I am creating a CSV Import for an application and basically want to be able to upload any CSV file, select the tables and fields to insert to and then click go.
I have most of this working (quite basic flow but it does the job)
one thing I got lost on though was this.
I want to upload ANY csv and to loop through the fields (seperated by say pipe) but I want to be able to count how many fields are in the flat file.
I know about explode using something like this
foreach($data as $key=>$element) {
$element = trim($element);
$pieces = explode("|", $element);
$field0 = $pieces[0];
$field1 = $pieces[1];
$field2 = $pieces[2];
}
but how do i count how many $pieces[#] there are??