miércoles, 27 de noviembre de 2024

check if a value is not or is in an array and create other array with those values

 <?php



$array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3, 'purple' => 4);

$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 2, 'cyan'   => 1);



$arr=array();



foreach($array1 as $value){

if (!in_array($value, $array2)) {

$arr[]=$value;

}


}


print_r($arr);



?>


Array ( [0] => 3 [1] => 4 )

No hay comentarios:

Publicar un comentario