donglou8371 2012-01-24 16:44
浏览 52
已采纳

用于检查PHP中的其他数组值的数组值?

I have an array $minus

array(3) { [0]=> string(6) "people" 
           [1]=> string(7) "friends" 
           [2]=> string(8) "siblings" 
         }

And I have an array $user

array(3) { ["people"]=> string(3) "100" 
           ["friends"]=> string(2) "10" 
           ["siblings"]=> string(2) "57" 
         }

I can get the values of $user by using the values of $minus like,

echo $user[$minus[0]] . ', ' . $user[$minus[1]] . ', ' . $user[$minus[2]];
// Would echo: 100, 10, 57

But how can I get the values of $user by using the values of $minus into a new array, the new array should be like,

array(3) { [0]=> string(3) "100" 
           [1]=> string(2) "10" 
           [2]=> string(2) "57" 
         }

I have tried using foreach loops but can never get it right?

  • 写回答

5条回答 默认 最新

  • doumanshan6314 2012-01-24 16:49
    关注
    foreach($minus as $key=>$value) {
      $new_array[$key] = $user[$value];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 使用Hadoop的MapReduce program
  • ¥15 Python发生IndexError错误如何解决?
  • ¥15 如何用matlab搭建激光器
  • ¥15 笔记本麦克风没有声音
  • ¥15 51单片机两路互补SPWM输出全桥逆变
  • ¥15 outlook左边用户名下拉为啥打不开了
  • ¥15 MATLAB程序不报错,内部函数体无法跳出循环
  • ¥15 #运行环境为.vue#试过data那里把属性设为0 return输出默认值(没用),但是我commodityList数组里已经包含了呀
  • ¥20 【matlab】已知功率谱密度反求时域信号
  • ¥15 麦当劳点餐系统代码纠错