-
Notifications
You must be signed in to change notification settings - Fork 19
Problem with Array_combine #16
Description
I always get the error on array_combine that the element are not the same so below my work around for array_combine
////////////////////////////////////////////////////////////////
function array_combine_special($header, $row, $pad = TRUE) {
$acount = count($header);
$bcount = count($row);
// more elements in $a than $b but we don't want to pad either
if (!$pad) {
$size = ($acount > $bcount) ? $bcount : $acount;
$header = array_slice($header, 0, $size);
$row = array_slice($row, 0, $size);
} else {
// more headers than row fields
if ($acount > $bcount) {
$more = $acount - $bcount;
// how many fields are we missing at the end of the second array?
// Add empty strings to ensure arrays $a and $b have same number of elements
$more = $acount - $bcount;
for($i = 0; $i < $more; $i++) {
$row[] = "";
}
// more fields than headers
} else if ($acount < $bcount) {
$more = $bcount - $acount;
// fewer elements in the first array, add extra keys
for($i = 0; $i < $more; $i++) {
$key = 'extra_field_0' . $i;
$header[] = $key;
}
}
}
return array_combine($header, $row);
}
However after this on this line of code (!$this->checkValidEmail($row['email'])) i get an undefined index email on the path
foreach ($rows as $key => $row) {
$row = $this->array_combine_special($header, $row);
$this->rows[] = $row;
// check for correct email
if (!$this->checkValidEmail($row['email'])) { /// undefined index email here
$row['message'] = 'Invalid email';
$this->errorRows[$key] = $row;
$this->valid = false;
} else {
$emails[] = $row['email'];
}
}
What can i do to fix this problem because i can not seem to get it