Compare multidimensional arrays in PHP

前端 未结 6 1042
情话喂你
情话喂你 2020-11-27 07:35

How can I compare multidimensional arrays in php? Is there a simple way?

6条回答
  •  臣服心动
    2020-11-27 07:54

    The simplest way I know:

    $a == $b;
    

    Note that you can also use the ===. The difference between them is:

    1. With Double equals ==, order is important:

      $a = array(0 => 'a', 1 => 'b');
      $b = array(1 => 'b', 0 => 'a');
      var_dump($a == $b);  // true
      var_dump($a === $b); // false
      
    2. With Triple equals ===, types matter:

      $a = array(0, 1);
      $b = array('0', '1');
      var_dump($a == $b);  // true
      var_dump($a === $b); // false
      

    Reference: Array operators

提交回复
热议问题