By default mysql_fetch_array returns numeric and associative array togeather. This function is useful for reading, while you can get values
either by statement : echo arr[1]; //circle or echo arr["shape"]; //circle
I am new to PHP and I run into the troubles when I wanted to change the values of that fetched array: arr[1] = square;
I supposed that arr["shape"] will be 'square' too, but I was wrong. arr["shape"] still remains 'circle'. Obviously you have to change both values to 'circle'.
Moreover: I wrote a funcion which should return changed shape array, (which is 2D array). I got different outcomes, if I used the first or
the second line of code.
function ChangeShape($arr)
{
for ($i=0; $i<$count($arr); $i++)
{
1. $arr[$i]["shape"] = 'square'; // fail to return changed $arr - it is (probably) reference to number counterpart
2. $arr[$i][2] = 'square'; // this WILL return changed $arr
}
}
return $arr;
}
My questions: 1. is there any technique in PHP by which I can change both values at once? 2. in my app I use assoc nicknames to access array values. But when it is not possible to change numeric alias at the same time, what is
the easiest way to do it?
thank for reading this to the end... hope you answer.
Thanks a lot.