Php array modulo every second value -


i have question. have array of alphabet. , every letter needs !$letter, needs echo out !b, !d, !f

i'm unsure how this. i've been told use modulo, % this.

but reading lot on internet , things haven't gotten clearer me.

i appreciate can me on matter! in advance!

foreach ($alphabet $i => $letter) {     echo (($i % 2) == 1 ? '!' : '') . $letter; } 

$i position of letter in array; since array indexes start 0, letters have odd indexes.

$i % 2 0 when $i even, 1 when it's odd. grade school arithmetic, should prerequisite programming career.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -