douliangpo0128
2018-02-09 22:53
浏览 49
已采纳

php在assoc数组中找到公共密钥

I have an array

  "a" => array:99 [▶]
  "b" => array:98 [▶]
  "c" => array:98 [▶]
  "d" => array:98 [▶]
  "e" => array:98 [▶]
  "f" => array:98 [▶]
  "g" => array:97 [▶]
  "h" => array:72 [▶]

.....

I need to filter the arrays by common keys. array a has 99 items and h has 72 items so I need to make all the arrays in this array the same 72 items based on the key.

array a:

"Johnson" => "2.94"
"Jordan" => "1.99"
"Bob" => "3.29"
"Bill" => "2.60"
"Jon" => "3.82"

......

array b:

"Johnson" => "2.94"
"Jordan" => "1.99"
"Bob" => "3.29"
"Bill" => "2.60"
"Steve" => "3.82"

......

so I essentially want the arrays a and b to be:

"Johnson" => "2.94"
"Jordan" => "1.99"
"Bob" => "3.29"
"Bill" => "2.60"

because these are the keys that are consistent across those 2 arrays.

I would need each of the arrays to have the same items based on the key that exists in all of the arrays.

Is there a way to do this if the arrays are part of the same array?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题