如何将数组与另一个数组stdclassobject进行比较并在php codeigniter中访问它的键

时间:2016-04-25 04:47:21

标签: php codeigniter

我正在使用带有codeigniter的php。当我做print_r时,我得到了以下内容:

Array
(
[0] => stdClass Object
    (
        [UserName] => fun
        [UserCode] => 6
        [GroupCode] => 1
        [GroupName] => Master
        [MenuCode] => 0
        [MenuName] => 
        [Admin] => 0
    )

[1] => stdClass Object
    (
        [UserName] => fun
        [UserCode] => 6
        [GroupCode] => 1
        [GroupName] => Master
        [MenuCode] => 1
        [MenuName] => Item Master
        [Admin] => 0
    )

)

另一方面,我有另一组数组,

Array
(
  [0] => Billing Report
  [1] => Waiterwise Report
  [2] => Admin
  [3] => User Master
  [4] => User Rights
  [5] => Close Session
  [6] => Close Day
)

现在我想比较上面两个数组中的Group名称,并希望将键作为结果。

1 个答案:

答案 0 :(得分:0)

试试这个

$result_array = array();
foreach($codeigniter_array as $k=>$r)
{
    foreach($r as $k1=>$r1)
    {
        if(in_array($r1, $group_array))
        {
            $result_array[$k1] =$r1;
        }
    }
}
print_r($result_array);die;