[英]Changing values in array based on values in another array
Here's an example in plain english of what I am trying to achieve: if the number given is 4, then I want to add 1 to every value that is equal to or less than 4 into the corresponding index of another array. 这是我要尝试实现的简单英语示例:如果给定的数字为4,那么我想将等于或小于4的每个值加1到另一个数组的相应索引中。 (hope that makes sense) (希望如此)
So my first array looks like this: 所以我的第一个数组看起来像这样:
Array ( [0] => 5 [1] => 6 [2] => 7 [3] => 4 [4] => 3 [5] => 2 [6] => 9 [7] => 8 [8] => 1 [9] => 10 [10] => 11 [11] => 12 [12] => 13 [13] => 14 [14] => 15 [15] => 16 [16] => 17 [17] => 18 )
The second array looks like this: 第二个数组如下所示:
Array ( [0] => 4 [1] => 3 [2] => 4 [3] => 4 [4] => 4 [5] => 5 [6] => 4 [7] => 4 [8] => 5 [9] => 4 [10] => 4 [11] => 5 [12] => 5 [13] => 4 [14] => 4 [15] => 4 [16] => 3 [17] => 3 )
And I am wanting the second array to look like this (after adding 1 to every value below 4 in the first array) so after the addition it would be 我希望第二个数组看起来像这样(在第一个数组中的每个低于4的值加1之后),所以添加后
Array ( [0] => 4 [1] => 3 [2] => 4 [3] => 5 [4] => 5 [5] => 6 [6] => 4 [7] => 4 [8] => 6 [9] => 4 [10] => 4 [11] => 5 [12] => 5 [13] => 4 [14] => 4 [15] => 4 [16] => 3 [17] => 3 )
In which index 3,4,5,9 have changed. 其中索引3、4、5、9已更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.