It looks nice. Can you please make me understand how it works
For example
function f($n){$s='';$b=str_pad('*',($m=$n*2+1),' ',2);for($i=0;$i<$m;++$i)$s.=($i==$n)?str_repeat('*',$m):$b;return chunk_split($s, $m);}
Output
*
*
*
*
*
***********
*
*
*
*
Let me write it in a way that is easier to see
$n = 5;
$row_len = $n*2+1;
$output = '';
//pad $n spaces on each side of *
$default = str_pad('*',$row_len,' ',2STR_PAD_BOTH); //is = " * "
//loop once for each vertical row (same as width)
for($i=0;$i<$row_len;++$i){
if($i==$n){
//do the center line all *'s
$output .= str_repeat('*',$row_len);//is = "***********"
}else{
//use the default line from above
$output .= $default;
}
}
//now we have a single line that is the length squared so we can chunk it
//into equal parts, to make a square
echo chunk_split($output, $row_len); //is = " * * ***********"
Basically we can create the " * " row by using string pad. Because we can pad spaces on both sides of a * up to the length of a row ($n*2)+1.
Then the center row, is just * so we can use string repeat to the length of the row for that line.
Last we take our big huge line of spaces and * and split it into chunks (\n) on the length of our row we want.