开发者

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

开发者 https://www.devze.com 2023-03-28 12:19 出处:网络
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 ther

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

精彩评论

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