如何过滤数组中的一些数值?(How to filter some numerical values from an array? [duplicate])

编程入门 行业动态 更新时间:2024-10-27 06:33:57
如何过滤数组中的一些数值?(How to filter some numerical values from an array? [duplicate])

这个问题在这里已经有了答案:

两个数组之间的差异 5个答案

我有一个数组$myArray1 ,其数值类似于2 5 7 13 23 25另一个数组$myArray2数值类似于3 4 7 11 13 25

我的要求是获得第三个数组$myArray3 ,只有$myArray3值不存在于$myArray2 ie 2 5 23

请告诉我任何PHP的功能?

This question already has an answer here:

difference between two arrays 5 answers

I have an array $myArray1 with some numerical values like 2 5 7 13 23 25 Another array $myArray2 has numerical values like 3 4 7 11 13 25

My requirement is to get a third array $myArray3 having only those values of $myArray1 that are not present in $myArray2 i.e. 2 5 23

Please tell me any function of php for this?

最满意答案

$myArray1=[2,5,7,13,23,25]; $myArray2=[3,4,7,11,13,25]; $myArray3=array_diff($myArray1,$myArray2); var_dump($myArray3); // 2, 5, 23 $myArray1=[2,5,7,13,23,25]; $myArray2=[3,4,7,11,13,25]; $myArray3=array_diff($myArray1,$myArray2); var_dump($myArray3); // 2, 5, 23

更多推荐

本文发布于:2023-08-04 23:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1424635.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数值   组中   filter   numerical   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!