Skip to content

Instantly share code, notes, and snippets.

@tonythere
Last active May 23, 2016 17:01
Show Gist options
  • Save tonythere/88e09c2d342043e3144c481b41c71f2d to your computer and use it in GitHub Desktop.
Save tonythere/88e09c2d342043e3144c481b41c71f2d to your computer and use it in GitHub Desktop.
<?php
/**
* Created by PhpStorm.
* User: phuong
* Date: 5/23/16
* Time: 22:54
*/
$m = 5;
$n = 4;
$col_span = 4;
$row_span = 4;
const star = 'O';
const space = ' ';
$records = [];
$total_horizontal_chars = $n * ($row_span - 1) + 1;
$total_vertical_chars = $m * ($col_span - 1) + 1;
for ($row = 0; $row < $total_vertical_chars; $row++) {
$record = '';
for ($col = 0; $col < $total_horizontal_chars; $col++) {
$thisChar = space;
if ($row % ($row_span - 1) == 0 || $col % ($col_span - 1) == 0) {
$thisChar = star;
}
$record = $record . $thisChar;
}
$records[] = $record;
}
$result = implode("\n", $records);
?>
<pre><?= $result; ?></pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment