Jump to content

counting troubles


lanu

Recommended Posts

Hi there,

My code here is meant to take the variable "$beyondportal" and see if it is a multiple of 26 counting from 0, then from 1, 2, 3 etc.. all the way to 25.

if it's a multiple of 26 counting from 1, I get a set of content. If it's a multiple of 26 counting from 1, I get another all the way through 25.

The code I wrote is working great if $beyond portal turns out to be a positive value, but if it's a negative value, this seems to be coming up wrong except for in the case of

multiples of 26 counting up from 0 because -26 is the same distance as 26 from zero.

Can someone see the pattern I'm getting at here?

 

 

 

<?php if ($beyondportal % 26 == 0 || $beyondportal == 0 || abs($beyondportal) % 26 == 0){ ?>

PURPLE

<?php } ; ?>

 

<?php if ($beyondportal % 26 == 1 || $beyondportal == 1|| abs($beyondportal) % 26 ==1){ ?>

BLUE

<?php } ; ?>

 

<?php if ($beyondportal % 26 == 2 || $beyondportal == 2|| abs($beyondportal) % 26 ==2){ ?>

GREEN

<?php } ; ?>

 

ETC... ETC.... up to:

 

<?php if ($beyondportal % 26 == 25 || $beyondportal == 25|| abs($beyondportal) % 26 ==25){ ?>

YELLOW

<?php } ; ?>

 

(my code on 1-25 is coming up incorrectly)

Link to comment
https://forums.phpfreaks.com/topic/254001-counting-troubles/
Share on other sites

change

<?php if ($beyondportal % 26 == 0 || $beyondportal == 0 || abs($beyondportal) % 26 == 0){ ?>
PURPLE    
<?php } ; ?>

to

<?php if ($beyondportal % 26 == 0){ ?>
PURPLE    
<?php } ; ?>

or

<?php if (abs($beyondportal) % 26 == 0){ ?>
PURPLE    
<?php } ; ?>

for all sace

Link to comment
https://forums.phpfreaks.com/topic/254001-counting-troubles/#findComment-1302111
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.