note 127036 rejected from function.getenv by cmb
| From: | cmb@php.net | Date: | Sat, 07 May 2022 11:24:24 +0000 |
| Subject: | note 127036 rejected from function.getenv by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218359@lists.php.net to get a copy of this message | ||
Note Submitter: benhut1 at gmail dot com
----
Using square brackets to access an array element by index number is not behaving as expected in PHP
7.1.7.
I use:
$myvar=getenv();
to get an array of all the environment variables, and then I try to use:
echo $myvar[0];
to try to display the first environment variable (regardless of the name of the variable), and I get
the error "PHP Notice: Undefined offset: 0 in - on line 4".
I even tried it with the with:
echo $myvar[1];
under the assumption that maybe the first index is actually 1 instead of zero, but then I again get
the error message "PHP Notice: Undefined offset: 1 in - on line 4". So it seems that
it's EXPECTING me to index by the name of the entry only (like the string "PATH" for
the index, instead of using an index number). I had assumed that a numerical index was a valid
alternative to using the name of the array entry, based on what I've read online, but it's
not working.