How can I make variable array available to whole code.
For example, I need to add integers to $ids[] inside one class or function so I can use it in regular code:
class displayClass {
public function display($field){
$fieldNum=0;
$puzzle=$field;
echo "<form action=\"index.php\" method=\"post\"><table border = \"3\" ><tr>" ;
for($i=1;$i<=36;$i++){
if($puzzle[$i]==0){
echo "<td><input type=\"text\" name=\"field".$i."\" maxlength=\"1\" size=\"1\"/></td>";
//problem is above... need to sava ids of fields..don't know how
} else {
echo "<td>".$puzzle[$i]."</td>";
}
if($i%6==0){
echo "</tr><tr>";
}
}
echo "</td></table></form>";
}
}
I need to add $i to a new existing array which is outside the class.
EDIT :
how can i fix this
Strict Standards: Non-static method displayClass::display() should not be called statically in Z:\dev\organization1\project1\htdocs\web\sudoku\index.php on line 35
If you’re having to do this then it’s a sign that you have design and architecture issues with the codebase you’re working with which are beyond the scope of this question.
However to solve your immediate problem, use the
globalkeyword:Assuming of course that
$ids[]is truly a gobally scoped variable and not defined within an existing function or class.