Php 仅比较和返回数组中的匹配项
我正在寻找一种方法(在PHP中)使用两个不同的数组来获得匹配项的结果。阵列是运动统计数据。一个数组包含统计数据的定义,另一个数组包含玩家的统计id和统计值。每个数组中的匹配项都是stat_id。我希望只返回两个数组中匹配项的结果 第一个数组包含stat定义。这是统计定义数组的药剂Php 仅比较和返回数组中的匹配项,php,arrays,Php,Arrays,我正在寻找一种方法(在PHP中)使用两个不同的数组来获得匹配项的结果。阵列是运动统计数据。一个数组包含统计数据的定义,另一个数组包含玩家的统计id和统计值。每个数组中的匹配项都是stat_id。我希望只返回两个数组中匹配项的结果 第一个数组包含stat定义。这是统计定义数组的药剂 [stat] => Array ( [0] => SimpleXMLElement Object ( [stat_id] =&
[stat] => Array
(
[0] => SimpleXMLElement Object
(
[stat_id] => 4
[enabled] => 1
[name] => Passing Yards
[display_name] => Pass Yds
[sort_order] => 1
[position_type] => O
)
[1] => SimpleXMLElement Object
(
[stat_id] => 5
[enabled] => 1
[name] => Passing Touchdowns
[display_name] => Pass TD
[sort_order] => 1
[position_type] => O
)
[2] => SimpleXMLElement Object
(
[stat_id] => 6
[enabled] => 1
[name] => Interceptions
[display_name] => Int
[sort_order] => 0
[position_type] => O
)
[3] => SimpleXMLElement Object
(
[stat_id] => 9
[enabled] => 1
[name] => Rushing Yards
[display_name] => Rush Yds
[sort_order] => 1
[position_type] => O
)
[4] => SimpleXMLElement Object
(
[stat_id] => 10
[enabled] => 1
[name] => Rushing Touchdowns
[display_name] => Rush TD
[sort_order] => 1
[position_type] => O
)
[5] => SimpleXMLElement Object
(
[stat_id] => 12
[enabled] => 1
[name] => Reception Yards
[display_name] => Rec Yds
[sort_order] => 1
[position_type] => O
)
[6] => SimpleXMLElement Object
(
[stat_id] => 13
[enabled] => 1
[name] => Reception Touchdowns
[display_name] => Rec TD
[sort_order] => 1
[position_type] => O
)
[7] => SimpleXMLElement Object
(
[stat_id] => 15
[enabled] => 1
[name] => Return Touchdowns
[display_name] => Ret TD
[sort_order] => 1
[position_type] => O
)
[8] => SimpleXMLElement Object
(
[stat_id] => 16
[enabled] => 1
[name] => 2-Point Conversions
[display_name] => 2-PT
[sort_order] => 1
[position_type] => O
)
[9] => SimpleXMLElement Object
(
[stat_id] => 18
[enabled] => 1
[name] => Fumbles Lost
[display_name] => Fum Lost
[sort_order] => 0
[position_type] => O
)
[10] => SimpleXMLElement Object
(
[stat_id] => 57
[enabled] => 1
[name] => Offensive Fumble Return TD
[display_name] => Fum Ret TD
[sort_order] => 1
[position_type] => O
)
[11] => SimpleXMLElement Object
(
[stat_id] => 19
[enabled] => 1
[name] => Field Goals 0-19 Yards
[display_name] => FG 0-19
[sort_order] => 1
[position_type] => K
)
[12] => SimpleXMLElement Object
(
[stat_id] => 20
[enabled] => 1
[name] => Field Goals 20-29 Yards
[display_name] => FG 20-29
[sort_order] => 1
[position_type] => K
)
)
这是玩家统计值数组
[stat] => Array
(
[0] => SimpleXMLElement Object
(
[stat_id] => 4
[value] => 0
)
[1] => SimpleXMLElement Object
(
[stat_id] => 5
[value] => 0
)
[2] => SimpleXMLElement Object
(
[stat_id] => 6
[value] => 0
)
[3] => SimpleXMLElement Object
(
[stat_id] => 9
[value] => 0
)
[4] => SimpleXMLElement Object
(
[stat_id] => 10
[value] => 0
)
[5] => SimpleXMLElement Object
(
[stat_id] => 12
[value] => 0
)
[6] => SimpleXMLElement Object
(
[stat_id] => 13
[value] => 0
)
[7] => SimpleXMLElement Object
(
[stat_id] => 15
[value] => 0
)
[8] => SimpleXMLElement Object
(
[stat_id] => 16
[value] => 0
)
[9] => SimpleXMLElement Object
(
[stat_id] => 18
[value] => 0
)
[10] => SimpleXMLElement Object
(
[stat_id] => 57
[value] => 0
)
)
我认为您正在寻找一个数组_intersect函数: