我有两个数组,希望找到arrayTwos值在arrayOne中的第一个匹配。
arrayOne ( [0] = C [1] = A [2] = B [3] = D [4] = B [5] = C)
和
arrayTwo ( [0] = A [1] = B [2] = C )
使用这些值,我希望返回值"C“,因为它是arrayTwo中第一个出现在arrayOne中的值。
我想我可以使用for循环,如果要运行语句,但是PHP中有函数可以用来简化这个过程吗?
下面的PHP代码从Google Merchant Centre中排除了Woocommerce类别。您将如何组合in_array以缩短代码?
// Exclude categories from my Google Product Feed
function lw_gpf_exclude_product($excluded, $product_id, $feed_format) {
// Return TRUE to exclude a product, FALSE to include it, $excluded to use the default behaviour.
$
假设我有2个数组。
array1:
value = 2
value = 1
value = 3
array2:
value = 1
value = 2
value = 3
value = 4
我想重新排列array1,使其具有与array2相同的排序,并删除在array2中找不到的值。我想遵循array2的排序,我不知道是否有一个现有的函数,如果有,请告诉我。谢谢。
我需要为ajax自动完成选择输入做三个数组的交集,所以有时一个或多个数组为空,array_intersect函数返回一个错误:array_intersect(): Argument #1 is not an array
$output['Family'] = array_intersect($temp['VernNamesSelected']['Family'], $temp['GenusSelected']['Family'], $temp['SpeciesSelected']['Fami
如何在另一个数组中搜索数组的元素?如果找到任何元素,则搜索函数返回true,否则返回false。
例如:
$mainArray = array(1,2,3,4,5);
$tosearch = array(2,7); //returns true as 2 is in main array.
$tosearch = array(7,8); //return false as no element found in main array.
我试图比较两个非关联数组,以创建一个新的数组与匹配。
不过,这就是我所拥有的:
//This array has several entries
$a_firstarray = Array();
//This array has less entries than the first array
$a_secondarray = Array();
//This array should contain the matches of the first array and the second array in no particular order
$a_mergedarray
fo