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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -