note 27546 deleted from language.variables.scope by cmb
| From: | cmb@php.net | Date: | Sun, 27 Oct 2019 08:31:34 +0000 |
| Subject: | note 27546 deleted from language.variables.scope by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212783@lists.php.net to get a copy of this message | ||
Note Submitter: wjs@sympaticoDOTca
----
Becareful where you define your global variables:
This will work:
<?php
$MyArray = array("Dog");
function SeeArray(){
global $MyArray;
if (in_array("Dog",$MyArray)){
foreach ($MyArray as $Element){
echo "$Element <hr/>";
}
}
}
SeeArray();
?>
while this will not:
<?php
SeeArray();
$MyArray = array("Dog");
function SeeArray(){
global $MyArray;
if (in_array("Dog",$MyArray)){ // an error will generate here
foreach ($MyArray as $Element){
echo "$Element <hr/>";
}
}
}
?>