+ 2
array
how I can get an array and filter out entries with odd index number
3 Antworten
+ 5
@Andika had given you a sample, the only thing you need to do if you want the even elements would be this line:
if($i%2==1){
Into this..
if($i%2==0){
That's it :)
P.S. The % between $i and 2 is called modulo operator, it returns a remainder of $i divided by 2, so, even numbers are fully divisible by two, while odd numbers are not, there's a remainder left from the division. Hope it can shed a light a little.
Hth, cmiiw
+ 3
yes,but I can't understand it,however what can I do for even index number?
+ 2
you mean like this? https://code.sololearn.com/wT8ujFJk557S/?ref=app