Skip to content

Instantly share code, notes, and snippets.

@dingdayu
Created July 24, 2017 03:54
Show Gist options
  • Save dingdayu/a5a6eadd6ade5d82fbdc6cebc6834682 to your computer and use it in GitHub Desktop.
Save dingdayu/a5a6eadd6ade5d82fbdc6cebc6834682 to your computer and use it in GitHub Desktop.
两个过滤数组key的方法
$fileArr = ['isVip', 'cover'];
$temp = [];
// 过滤方案一
foreach ($fileArr as $item) {
if(array_key_exists($item, $movie)) {
$temp[$item] = $movie[$item];
}
}
// 过滤方案二
foreach ($movie as $key => $val) {
if(in_array($key, $fileArr)) $temp[$key] = $val;
}
if(empty($temp)) return null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment