Comparing two almost exact arrays I have two arrays:


$row
$rowTwo


The only difference between these two arrays are the first two keys have slightly different names due problems out of my control.

I'm wondering if there is a cleaner way to do it. Or would it be simply easier to find a way to rename the arrays to match?

        $needUpdate = false;

        if (strcasecmp( $row['Trelease'] , $rowTwo['release'] ) != 0) {
            $needUpdate = true;
        }  else if (strcasecmp( $row['dateTime'] , $rowTwo['date'] ) != 0) {
            $needUpdate = true;
        } else if (strcasecmp( $row['defectID'] , $rowTwo['defectID'] ) != 0) {
            $needUpdate = true;
        } else if (strcasecmp( $row['type'] , $rowTwo['type'] ) != 0) {
            $needUpdate = true;
        } else if (strcasecmp( $row['severity'] , $rowTwo['severity'] ) != 0) {
            $needUpdate = true;
        } else if (strcasecmp( $row['summary'] , $rowTwo['summary'] ) != 0) {
            $needUpdate = true;
        }  else if (strcasecmp( $row['status'] , $rowTwo['status'] ) != 0) {
            $needUpdate = true;
        }  else if (strcasecmp( $row['link'] , $rowTwo['link'] ) != 0) {
            $needUpdate = true;
        }
http://php.net/array_diff


  Compares array1 against one or more other arrays and returns the values in array1 that are not present in any of the other arrays. 


// Set the keys matching to the $rowTwo array
$row['release'] = $row['Trelease'];
$row['date'] = $row['dateTime'];

// Unset the original values as we no longer need these
unset($row['Trelease'], $row['dateTime']);

// Compare them:
$difference = array_diff($row, $rowTwo);
$needUpdate = count($difference)!==0;