note 127036 added to function.getenv
| From: | benhut1 at gmail dot com | Date: | Fri, 06 May 2022 22:07:33 +0000 |
| Subject: | note 127036 added to function.getenv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218356@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.47 (proxied: 98.232.70.175)
----
Manual Page -- https://php.net/manual/en/function.getenv.php
Edit -- https://main.php.net/note/edit/127036
Del: integrated -- https://main.php.net/note/delete/127036/integrated
Del: useless -- https://main.php.net/note/delete/127036/useless
Del: bad code -- https://main.php.net/note/delete/127036/bad+code
Del: spam -- https://main.php.net/note/delete/127036/spam
Del: non-english -- https://main.php.net/note/delete/127036/non-english
Del: in docs -- https://main.php.net/note/delete/127036/in+docs
Del: other reasons-- https://main.php.net/note/delete/127036
Reject -- https://main.php.net/note/reject/127036
Search -- https://main.php.net/manage/user-notes.php