PHP关联数组的相等性 [英] Equality of PHP associative arrays

查看:61
本文介绍了PHP关联数组的相等性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关PHP关联数组的快速问题.

Quick question about PHP associative arrays.

说有两个数组:

$A = array("AAA" => "45", "FFF" => "108", "GGG" => "15"); 

$B = array("FFF" => "108", "GGG" => "15", "AAA" => "45");

这些数组相等吗?条目在关联数组中的位置重要吗?

Are these arrays equal? Does the position of an entry in associative arrays matter?

推荐答案

根据PHP官方文档:

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

$ a == $ b 如果 $ a $ b 具有相同的键/值对,则为TRUE.

$a == $b TRUE if $a and $b have the same key/value pairs.

$ a === $ b 如果 $ a $ b 具有相同的键/值对且顺序相同,则为TRUE,并且相同的类型.

$a === $b TRUE if $a and $b have the same key/value pairs in the same order and of the same types.

$A=array ("AAA"=>"45", "FFF"=>"108", "GGG"=>"15");
$B=array ("FFF"=>"108", "GGG"=>"15", "AAA"=>"45");

var_dump($A==$B);

bool(true)

bool(true)

var_dump($A===$B);

布尔(假)

这篇关于PHP关联数组的相等性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆