Comparing with the values ​​of two arrays in PHP

Hi, I want to compare all values ​​from 2 arrays and end up with true or false. I am using the code below and thought the result would be false. but this is not the case when the last line is started, I expect something like

Array ([0] => 0)

but I do not see the display, so suppose php is happy that there is no difference

my code

        $before = array('1', '1', '0', '0', '1', '0' ) ;
        $after =  array('0', '1', '0', '0', '1', '0' ) ;

        $new_array= array_diff($before,$after);

        print_r ($new_array) ;

sure array_diff should notice the difference here? any help would be greatly appreciated

+3
source share
5 answers

array_diffgives which elements are in $before, but not $after. Since both arrays are composed of '0'and '1', it returns an empty array.

, , array_diff_assoc, .

, Array( [0] => 0 ), Array( [0] => 1 ), , .

, array_diff_assoc($after, $before).

+8
    $before = array('1', '1', '0', '0', '1', '0' ) ;
    $after =  array('0', '1', '0', '0', '1', '0' ) ;

    $new_array= array_diff_assoc($before,$after);

    print_r ($new_array) ;
+3
+1

, array_diff . . 0 0 1 1. , Array1 Array2... ArrayN. Array1, , true/false boolean. . 1 .

0

Hi, I want to compare all values ​​of 2 arrays and end up with true or false

$bool = ($array1 == $array2);

http://us2.php.net/manual/en/language.operators.array.php

0
source

Source: https://habr.com/ru/post/1740962/


All Articles