一个数字的阵列有数字数组:过滤根据数值图形
$list = array
(
[0] => 111
[1] => 112
[2] => 113
[3] => 114
[4] => 121
[5] => 122
[6] => 123
[7] => 124
[8] => 131
[9] => 132
[10] => 1234
[11] => 1123
[12] => 1223
[13] => 1233
[14] => 4321
)
和可变(图案):
$input = 1231;
我想与阵列过滤以下规则。假设$list[$i]
是$list
数组的一个项目,$d
是$list[$i]
的数字。然后
- 如果位数等于
$list[$i]
$d
计数大于位数等于$input
$d
计数值,则该数组项必须被跳过; - 如果在
$input
中没有指定$d
数字,则必须跳过数组项。
例如,在上述的可变$input
1
出现了两次,2
和3
出现一次。$list = array ( [0] => 111 ==> should be removed (1 is only defined twice in $input, so it shouldn't appear more than twice) [1] => 112 [2] => 113 [3] => 114 ==> should be removed (there is no 4) [4] => 121 [5] => 122 ==> should be removed (2 is only defined once, so it shouldn't appear more than once) [6] => 123 [7] => 124 ==> should be removed (there is no 4) [8] => 131 [9] => 132 [10] => 1234 ==> should be removed (there is no 4) [11] => 1123 [12] => 1223 ==> should be removed (2 is only defined once in $input, so it shouldn't appear more than once) [13] => 1233 ==> should be removed (3 is only defined once in $input, so it shouldn't appear more than once) [14] => 4321 ==> should be removed (there is no 4) )
如何实现这一点:
然后在出现比这更应该一切从阵列中删除?
为什么111,112 ..应该被删除? –
你可以尝试[substr_count](http://php.net/manual/en/function.substr-count.php)和[array_filter](http://php.net/manual/en/function.array -filter.php) –
为什么在世界范围内'111'应该被移除并且'123'停留?这背后的逻辑是什么。你需要告诉我们的原因不只是你想要的结果。 – Irvin