array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

array

how I can get an array and filter out entries with odd index number

25th Nov 2017, 9:07 PM
zahra kazemi
3 Answers
+ 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
26th Nov 2017, 8:08 AM
Ipang
+ 3
yes,but I can't understand it,however what can I do for even index number?
26th Nov 2017, 5:52 AM
zahra kazemi
25th Nov 2017, 11:22 PM
Andika Romansyah