PHP 8.5.0 Released!

Voting

: zero minus zero?
(Example: nine)

The Note You're Voting On

Tim Trefren
17 years ago
Here's a little wrapper for array_diff - I found myself needing to iterate through the edited array, and I didn't need to original keys for anything.

<?php
function arrayDiff($array1, $array2){
    # This wrapper for array_diff rekeys the array returned
    $valid_array = array_diff($array1,$array2);
    
    # reinstantiate $array1 variable 
    $array1 = array();
    
    # loop through the validated array and move elements to $array1
    # this is necessary because the array_diff function returns arrays that retain their original keys
    foreach ($valid_array as $valid){
        $array1[] = $valid;
        }
    return $array1;
    }
?>

<< Back to user notes page

To Top