Hi there,

I have set myself the task of writing a program to fill in a blank sudoku grid. In some ways I wish I hadn’t, but none the less it has forced me to begin to understand classes and objects.

Ok, now a brief outline of what I am trying to achieve:

Create 81 objects with the class Cell. Cell contains several vars:

x - the x co-ordinate (1-9)

y - the y co-ord

value - the chosen number for this cell

options - and array of possible numbers for this cell

remaining - the number of options available for this cell

The idea is to select a number at random from the options array and move it into the value variable, then remove that number from every cell that is affected by this move (ie, any cell in the same row, column, or block).

This process is repeated on the next cell with the lowest number of options remaining, until the grid is filled in.

At the moment I have a belief that (fingers crossed) this method will require no backtracking. However I may be wrong, but either way I shall worry about that bridge when I come to it.

So in the meantime, I need to know how to grab all the objects with class of Cell, and with an x value of say 1, then update their options array. As I’m new to objects and classes, I’m not sure how to do this (and in the most efficient way).

I tried this:

```
function updateRowOptions($x, $n){
$i = 1;
while($i <= 81){
$cellname = 'cell' . $i;
$vars = get_object_vars($$cellname);
if($vars['x'] == $x){
$array = $vars['options'];
$offset = array_search($n, $array);
$array = array_splice($array, $offset, 1);
$$cellname->options = $array;
}
$i++;
}
}
```

But $$cellname, is not behaving as the object $cell1, for example, so I get an error. Also, even if it did work, it seems mightily inefficient, since I have to iterate through each cell 3 times on each move (once for row, column and block).

What is the best way to select objects based on their contents?

Many thanks,

Mike