Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Problem with Array_combine #16

@tjlawy

Description

@tjlawy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions