Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.