I have some problem with array declared as global.
first example, without global declaration:
Code: Select all
$name = array("cat"=>"pussy","dog"=>"rex");
$name["cat"] = "tom" ;
$a = "dog" ;
$name[$a] = "snoopy" ;
$Txt = "" ;
$i = 0 ;
foreach($name as $sKey => $sValue) {
$i++;
$Txt .= "- $i : $sKey = $sValue" . <crlf> ;
}
echo $Txt ;
- 1 : cat = tom
- 2 : dog = snoopy
Then, just adding global declaration
Code: Select all
global $name[] ;
$name = array("cat"=>"pussy","dog"=>"rex");
$name["cat"] = "tom" ;
$a = "dog" ;
$name[$a] = "snoopy" ;
$Txt = "" ;
$i = 0 ;
foreach($name as $sKey => $sValue) {
$i++;
$Txt .= "- $i : $sKey = $sValue" . <crlf> ;
}
echo $Txt ;
- 1 : cat = tom
- 2 : dog = rex
- 3 : $a = snoopy
Is there any limitation with global array that I missed?
(Windows 11 22H2, XYplorer 24.20)