Skip to content

Instantly share code, notes, and snippets.

@faridlab
Created February 16, 2017 09:40
Show Gist options
  • Save faridlab/30b4ee2bec77b7b2a9e6e1494eab2e6b to your computer and use it in GitHub Desktop.
Save faridlab/30b4ee2bec77b7b2a9e6e1494eab2e6b to your computer and use it in GitHub Desktop.
Anu gemes looping
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Anu</title>
</head>
<body>
<table>
<?php for ($i=0; $i < 5; $i++): ?>
<tr>
<?php for ($j=($i*5); $j < (($i + 1) * 5); $j++): ?>
<td><?php echo ($j + 1); ?></td>
<?php endfor; ?>
</tr>
<?php endfor; ?>
</table>
</body>
</html>
----
<?php
$data = array();
for ($i=0; $i < 5; $i++):
for ($j=($i*5); $j < (($i + 1) * 5); $j++):
$data[$i][] = ($j + 1);
endfor;
if($i % 2 == 1) $data[$i] = array_reverse($data[$i]);
endfor;
$result = array();
for ($i=0; $i < 5; $i++):
for ($j=0; $j < 5; $j++):
$result[$i][] = $data[$j][$i];
endfor;
endfor;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Gemes</title>
</head>
<body>
<table>
<?php for ($i=0; $i < 5; $i++): ?>
<tr>
<?php for ($j=0; $j < 5; $j++): ?>
<td><?php echo $result[$i][$j]; ?></td>
<?php endfor; ?>
</tr>
<?php endfor; ?>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment