There is another solution to your problem. You can set it like that and be sure you pick only 10 positions in limited set of coordinates:
<?php
// build minefield
$minefield = array();
for($x=1; $x<=9; $x++) {
$minefield[$x] = array();
for($y=1; $y<=9; $y++) {
$minefield[$x][$y] = 0;
}
}
// prepare cartesian func
function array_cartesian() {
$_ = func_get_args();
if(count($_) == 0)
return array(array());
$a = array_shift($_);
$c = call_user_func_array(__FUNCTION__, $_);
$r = array();
foreach($a as $v)
foreach($c as $p)
$r[] = array_merge(array($v), $p);
return $r;
}
// get coordinates
$coords = array_cartesian(range(1,9), range(1,9));
// pick random coordinates' keys
$chosen_coords = array_rand($coords, 10);
foreach ($chosen_coords as $key) {
$minefield[$coords[$key][0]][$coords[$key][1]] = 'X';
}
I know, it is lengthy, but I could write it in 2-3 lines in Python.
Ps. The code for cartesian product is from here: https://stackoverflow.com/a/2516779/548696