n-queens problem, displaying more than one solution available
PHP

Using a simple recursive approach.

&lt;?
function q($n,$t=[],$r=1,$S=str_repeat){
  foreach($r&gt;$n?$t:[]as$v)echo$f=$S('+---',$n)."+\n",$S('|   ',$n)."|\n"|$S(' ',$v*4-2).q;
  for(;$s&lt;$n?$r-$s^abs($c=$p-$t[$s++])&amp;&amp;$c:q($n,$t+[$r=&gt;$p],$r+1)?:$n&gt;=$p+=$s=1;);echo$f;
}
q(4);


Sample output for $n=4:

+---+---+---+---+
|   | q |   |   |
+---+---+---+---+
|   |   |   | q |
+---+---+---+---+
| q |   |   |   |
+---+---+---+---+
|   |   | q |   |
+---+---+---+---+
+---+---+---+---+
|   |   | q |   |
+---+---+---+---+
| q |   |   |   |
+---+---+---+---+
|   |   |   | q |
+---+---+---+---+
|   | q |   |   |
+---+---+---+---+