I have the import function working, E.G it does import the users into the db, however, when my function gets to the end of the CSV file it adds an empty array and, of course, gives me a mysql error because of the null entries of the last array.
I'm trying to figure out how to select and erase empty arrays from the multidimentional array $lineItem2, and have been working on it all day, but the solution eludes me.
First, here is what the array looks like after its imported and processed:
(note the empty array at bottom)
Code: Select all
Array(
[0] => Array(
[fname] => Todd
[lname] => Preston
[email] => tpreston@somewhere.com)
[1] => Array(
[fname] => Sam
[lname] => Phillips
[email] => sphillips@somewhere.net)
[2] => Array(
[fname] =>
[lname] =>
[email] => )
)$lineItem2 is the multidimensional array that contains all the user info.
Code: Select all
foreach($lineItem2 as $key => $value){
//fname is the first value in each array, if it's empty, drop it.
if($value['fname'] === ''){
unset($key); //not working
}
//set values for db insertion
$fname = $value['fname'];
$lname = $value['lname'];
$email = $value['email'];
//insert new array values into db
$userAdmin->import_users($fname,$lname,$email);
}I'm sure there are a lot of other, more desirable/efficient ways to do this, but like I said I'm still new to PHP and still learning...
Any help would be greatly appreciated, thanks!