Php 如果第二个数组键等于

Php 如果第二个数组键等于,php,arrays,function,compare,exists,Php,Arrays,Function,Compare,Exists,我有两个阵列: $choices = array ( [model] => 3D Modeling / BIM [edb] => Engineering & Design-Build [gse] => Green & Sustainable Energy [ipd] => Integrated Project Design [lc] => Lean Constructi

我有两个阵列:

$choices = array  (
        [model] => 3D Modeling / BIM
        [edb] => Engineering & Design-Build
        [gse] => Green & Sustainable Energy
        [ipd] => Integrated Project Design
        [lc] => Lean Construction
        [mt] => Material Supply
        [ecs] => Electrical Construction & Service
        [fps] => Fire Protection Services
        [hms] => HVAC & Mechanical Service
        [tsl] => Traffic Signal & Lighting
    )
$servicesSelected = array (
        [model] => 0
        [ipd] => 1
        [lc] => 2
        [mt] => 3
    )
我试图检查是否有任何数组2键等于数组1键,如果该键等于数组2键,则打印数组1中的值。我不完全确定从哪里开始。但在这个例子中,我会附和以下内容,因为它们的基伊存在于比较中

  • 三维建模/BIM
  • 综合项目设计
  • 精益建设
  • 物资供应
    • 这应该可以做到:

      <?php
      header('Content-Type:text/plain');
      $choices = array  (
      'model' => ' 3D Modeling / BIM',
      'edb' => ' Engineering & Design-Build',
      'gse' => ' Green & Sustainable Energy',
      'ipd' => ' Integrated Project Design',
      'lc' => ' Lean Construction',
      'mt' => ' Material Supply',
      'ecs' => ' Electrical Construction & Service',
      'fps' => ' Fire Protection Services',
      'hms' => ' HVAC & Mechanical Service',
      'tsl' => ' Traffic Signal & Lighting');
      $servicesSelected = array (
      'model' => 0,
      'ipd' => 1,
      'lc' => 2,
      'mt' => 3);
      
      $printArray = array_intersect_key($choices , $servicesSelected );
      
      var_export($printArray);
      ?>
      
      这样做

      foreach($servicesSelected as $key2=>$serviceSelected)
        foreach($choices as $key1=>$choice)
          if($key1==$key2) echo $choice;
      

      一个普通的循环?令人惊叹的!!我走上了正确的道路,使用了其他一些php函数。非常感谢。
      foreach($servicesSelected as $key2=>$serviceSelected)
        foreach($choices as $key1=>$choice)
          if($key1==$key2) echo $choice;