Skip 2 digits after print 2 digits

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anaspk
Forum Newbie
Posts: 7
Joined: Wed Mar 25, 2009 1:38 am

Skip 2 digits after print 2 digits

Post by anaspk »

hi,
i need a php code which work in such a way that it skip 2 digits after printing 2 digits:
example:

1,2, 5,6, 9,10, 13,14.........

i now some for looping techniques will do this but don't know hoe please help me
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Skip 2 digits after print 2 digits

Post by AbraCadaver »

Many ways:

Code: Select all

for($i=0; $i<=100; ($i % 2 == 0) ? $i+=2 : $i) {
	echo ++$i . ',';
}

for($i=0; $i<=100; ($i % 2) ? $i : $i+=2) {
	echo ++$i . ',';
}

for($i=0; $i<=100; !($i % 2) ? $i+=2 : $i) {
	echo ++$i . ',';
}

for($i=1; $i<=100; $i++) {
	echo $i . ',';
	$i = ($i % 2 == 0) ? $i+=2 : $i;
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply