I am trying to remove two key value pairs from an array, I am using the code below to segregate out the keys I don't want. I don't understand why it is not equating properly. if I remove the OR (|| $key != 6
) it will work properly but I was hoping to have one if statement. Can anyone explain what I'm doing wrong? Thanks.
$test = array( '1' => '21', '2' => '22', '3' => '23', '4' => '24', '5' => '25', '6' => '26' );
foreach( $test as $key => $value ) {
if( $key != 4 || $key != 6 ) {
$values[$key] = $value;
echo '<br />';
print_r( $values );
}
}
// Output
Array ( [1] => 21 [2] => 22 [3] => 23 [4] => 24 [5] => 25 [6] => 26 )