PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I wonder if someone can help me understand this. I can access global variable from inside the function but not a global array. How do I add value to my array then?
<?
$attributes[] = ""; // a blank array
$optionCounter=0; // a global variable
function setOption($a){
global $optionCounter; //accessing global variable - works fine
global $attributes // accessing global array - doesn't work
//add attribute to attribute array
$attributes[] = $a; // this doesn't work either coz access to global array failed
//increment optionCounter by one
$optionCounter++; // works fine
}
//test time
setOption("Size");
?>
//create an array with no element to store all the attributes (i.e options)
$attributes = array();
// ************ function to set option for product entry ***********
function setOption($a){
global $attributes;
//insert an element to the global array
$attributes[] = $a;
}
setOption("Size");
setOption("Colour");