Tuesday, 15 July 2014

php - Get current number of columns in alternating rows -



php - Get current number of columns in alternating rows -

i need write php function, in fact have math question.

i have variable number of results. want print results in alternating rows of 3 , 4 columns. so, have know each result, in type of row located (aka, how many columns it's row has).

an illustration of result

ik know can in php using 2 variables, assume there if mathematical function calculate each item (which has index starting @ 0) in type of row situated.

you can utilize formula determine on kind of row at.

$classname = (($index % 7) < 3 ? 'row-with-three' : 'row-with-four')

since pattern repeats every 7 objects start wrapping value around, $index % 7. provide value between 0 , 6 inclusively. can check if it's 1 of first 3 doing < 3, if it's row has 3 objects. otherwise has 4 objects.

php math optimization

No comments:

Post a Comment