php搜索二维数组

时间:2017-08-09 07:00:52

标签: php arrays associative-array

我开发的程序可以获得包含user_id及其技能的用户技能数组,这个数组如下:

array(4) {
   [17]=>
     array(3) {
        [0]=>
          string(8) "word"
        [1]=>
          string(10) "power point"
        [2]=>
          string(28) "excel"
       }
   [16]=>
    array(3) {
    [0]=>
     string(14) "english
    [1]=>
     string(14) "french"
    [2]=>
    string(12) "farsi"
  }
 }

键是user_id,值是技能数组,现在我想搜索有两个值的user_ids:英语或单词,我希望返回17,16,我该怎么做? ,谢谢你的帮助:)

1 个答案:

答案 0 :(得分:2)

使用import { browser, Config } from 'protractor'; export let config: Config = { seleniumAddress: 'http://127.0.0.1:4444/wd/hub', SELENIUM_PROMISE_MANAGER: false, baseUrl: 'http://www.google.com', capabilities: { browserName: 'chrome' }, framework: 'custom', frameworkPath: require.resolve('protractor-cucumber-framework'), specs: [ '../../features/*.feature' ], onPrepare: () => { browser.ignoreSynchronization = true; browser.manage().window().maximize(); }, cucumberOpts: { compiler: "ts:ts-node/register", strict: true, format: ['pretty'], require: ['../../stepdefinitions/*.ts', '../../support/*.ts'] } 函数的解决方案:

array_intersect

输出:

$arr = [ 17 => ["word", "power point", "excel"], 16 => ["english", "french", "farsi"] ];
$search_keys = ["english", "word"];
$keys = [];

foreach ($arr as $k => $v) {
    if (array_intersect($search_keys, $v)) $keys[] = $k;
}

print_r($keys);