Difference between revisions of "Talk:PHP u1v2"

From Ilianko
(Created page with "2. <code><pre><?php $files = array(); $dir = opendir('images'); while( $file = readdir($dir)) { if( !is_dir($file)) { $files[] = $file; }...")
 
Line 16: Line 16:
 
?>
 
?>
 
<img src=images/<?php echo $filename; ?> alt="fourth image" title="fourth image" />
 
<img src=images/<?php echo $filename; ?> alt="fourth image" title="fourth image" />
 +
</pre></code>
 +
<code><pre>
 +
<?php
 +
 +
$files = array();
 +
$dir = opendir('images');
 +
 +
while( $file = readdir($dir))
 +
{
 +
if( !is_dir($file))
 +
{
 +
$files[] = $file;
 +
}
 +
}
 +
$filename1 = $files[rand(0, sizeof($files)-1)];
 +
 +
$filename2 = $filename1;
 +
while( $filename1 == $filename2 )
 +
{
 +
$filename2 = $files[rand(0, sizeof($files)-1)];
 +
}
 +
?>
 +
<img src=images/<?php echo $filename1; ?> alt="fourth image" title="fourth image" />
 +
<img src=images/<?php echo $filename2; ?> alt="fourth image" title="fourth image" />
 
</pre></code>
 
</pre></code>

Revision as of 18:58, 8 November 2015

2.

<?php
			
			$files = array();
			$dir = opendir('images');
			
			while( $file = readdir($dir))
			{
				if( !is_dir($file))
				{
					$files[] = $file;
				}	
			}
			$filename = $files[rand(0, sizeof($files)-1)];
		?>
		<img src=images/<?php echo $filename; ?> alt="fourth image" title="fourth image" />
<?php
			
			$files = array();
			$dir = opendir('images');
			
			while( $file = readdir($dir))
			{
				if( !is_dir($file))
				{
					$files[] = $file;
				}	
			}
			$filename1 = $files[rand(0, sizeof($files)-1)];
			
			$filename2 = $filename1;
			while( $filename1 == $filename2 )
			{
				$filename2 = $files[rand(0, sizeof($files)-1)];
			}
		?>
		<img src=images/<?php echo $filename1; ?> alt="fourth image" title="fourth image" />
		<img src=images/<?php echo $filename2; ?> alt="fourth image" title="fourth image" />