Jump to content

[SOLVED] What does the "%" character do?


HoTDaWg

Recommended Posts

hi im currently learing php from a book and it did not explain the purpose of a % in an if statement:

<?php
if(($x % $perrow) ==0)
{
  print "the staement ...";
}
//it also uses it later...
if (($x % perrow) != 0) 
{
   print "another statement";
} else {
   print "the final statement";
?>

the script basically outputs all the images it finds in a folder and places each inside of a table.  The full code is:

<?php
error_reporting(E_ALL);
$fdir = "Uploads";
$files = array();

print <<<HTML
<html>
<body>
HTML;

($dir = opendir($fdir)) or die ("Cannot open \"$fdir\"");

$grphnum = 0;

while(!($file= readdir($dir)) === FALSE) 
{
if (strpos($file,".png") || strpos($file,".gif") || strpos($file,".jpg"))
{
	$grphnum++;
	$files["$grphnum"] = $fdir."/".$file;
}
}
closedir($dir);

array_multisort($files,SORT_ASC,SORT_STRING);

print "\t<table border=1>\n";
print "\t<tr height=\"60\">\n";

$perrow=5;

for ($x=1; $x <= $grphnum; $x++)
{
print "\t\t<td><img src=".$files["$x"]." width=\"50\"></td>\n";
if (($x % $perrow) == 0)
{
	print "\t</tr>\n\t<tr height=\"60\">\n";
}
}

if (($x % $perrow) != 0)
{
print "\t\t<td> </td>\n\t</tr>\n";
}else{
print "\t</tr>\n";
}

print "\t</table>\n";

print <<<html
</body>
</html>
html;
?>

 

so my quesiton what does the % do and why is it being used?

any help would be greatly appreciated thanks

Link to comment
https://forums.phpfreaks.com/topic/138220-solved-what-does-the-character-do/
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.