[英]Array_Filter/Array_Unique on an Array of Arrays?
I want to perform the following action on an array of arrays: 我想对数组数组执行以下操作:
$fix = array($array1, $array2, $array3, $array4);
foreach ($fix as &$f){
$f = array_filter(array_unique($f));
}
Unfortunately, despite my efforts to pass each array by reference, I'm not getting filtered and uniquified results at the end of the process. 不幸的是,尽管我努力通过引用传递每个数组,但在过程结束时并没有得到过滤和统一的结果。 Is there a simple way to get this done?
有没有简单的方法可以做到这一点? Or should I approach this problem in a different way?
还是应该以其他方式解决这个问题? I can just call the filtering etc on each array in turn, which works, but it seems like that can't be the DRY way to go...
我可以依次调用每个数组上的过滤等,这是可行的,但似乎这不是DRY的方法...
$fix = array($array1, $array2, $array3, $array4);
foreach ($fix as $k => $v){
$fix[$k] = array_filter(array_unique($v));
}
Based on comments, a way to change the original variables: 基于注释,一种更改原始变量的方法:
$fix = compact($array1, $array2, $array3, $array4);
foreach ($fix as $k => $v){
$fix[$k] = array_filter(array_unique($v));
}
extract($fix);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.