开发者

How to search(matchings) more than one values in an php array?

In php we have ar开发者_如何转开发ray_search() to search a value in an array. According to my knowledge it can search only one value at a time. How to search more that one values in an array. Are there any functions to do so.

Thanks


I'm not sure if there is a function for it, but you could do that in a foreach loop quite easily.

<?php

$array('some', 'values', 'here');
$values = array('values', 'to', 'find');

foreach($values as $v) {
  $key = array_search($v, $array):
  if ($key) {
    $new_array[] = $array[$key];
  }
}

?


try this:

$array = array('some', 'values', 'here');
$values = array('values', 'to', 'find');

foreach($values as $v) {
  $key = array_search($v, $array);
  if ($key) {
    $new_array[] = $array[$key];
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜