Arrays Examples
An array is a special variable that can hold more than one value. In PHP an array has no pre-determined length and will automatically expand to fit any number of values
Wednesday
Array
array(7) { [0]=> string(6) "Sunday" [1]=> string(6) "Monday" [2]=> string(7) "Tuesday" [3]=> string(9) "Wednesday" [4]=> string(8) "Thursday" [5]=> string(6) "Friday" [6]=> string(8) "Saturday" }Array
(
[0] => Sunday
[1] => Monday
[2] => Tuesday
[3] => Wednesday
[4] => Thursday
[5] => Friday
[6] => Saturday
)
7
http://google.com
array(6) { ["facebook"]=> string(19) "http://facebook.com" ["google"]=> string(17) "http://google.com" ["pinterest"]=> string(20) "http://pinterest.com" ["twitter"]=> string(18) "http://twitter.com" ["mashable"]=> string(19) "http://mashable.com" ["humber"]=> string(16) "http://humber.ca" }Array
(
[facebook] => http://facebook.com
[google] => http://google.com
[pinterest] => http://pinterest.com
[twitter] => http://twitter.com
[mashable] => http://mashable.com
[humber] => http://humber.ca
)
Load and Array with Glob Function
Array
(
[0] => images/Gallery/thumbnails/Mountains.jpg
[1] => images/Gallery/thumbnails/Retro-Downtown.jpg
[2] => images/Gallery/thumbnails/Skyline-2.jpg
[3] => images/Gallery/thumbnails/Skyline-4.jpg
[4] => images/Gallery/thumbnails/Skyline.jpg
[5] => images/Gallery/thumbnails/Train-Station.jpg
[6] => images/Gallery/thumbnails/Vancouver-Library.jpg
[7] => images/Gallery/thumbnails/Vancouver-Port.jpg
[8] => images/Gallery/thumbnails/boats.jpg
)
-
Mountains -
Retro Downtown -
Skyline 2 -
Skyline 4 -
Skyline -
Train Station -
Vancouver Library -
Vancouver Port -
Boats
Superglobal Arrays in PHP
Predefined arrays that automatically populate for you by PHP.
Examples:
- $_SERVER: information about the server environment.
- $_POST: all form data that was submitted using th POST method.
- $_GET: all form data that was submitted using the GET method.
- $_FILES: all the uploaded files submitted through a form.
- $_REQUEST: all the info from a form submission (combination of get/post/file) - avoid using this as it can introduce security problems.
- $_COOKIE: data stored in a browser cookie.
- $_SESSION: stores browser session data on the server.
Entire PHP Server Array
Array
(
[LSPHP_ENABLE_USER_INI] => on
[PATH] => /usr/local/bin:/usr/bin:/bin
[TEMP] => /tmp
[TMP] => /tmp
[TMPDIR] => /tmp
[PWD] => /
[HTTP_ACCEPT] => */*
[HTTP_ACCEPT_ENCODING] => gzip, br, zstd, deflate
[CONTENT_LENGTH] => 0
[HTTP_HOST] => www.phpbasics.brettmcsherry.com
[HTTP_USER_AGENT] => Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
[UNIQUE_ID] => aVEEYDGpvCld3Xuo4NnBtQACIxc
[USER_ID] => 9071211
[DATABASE_SERVER] => localhost
[SITE_ROOT] => /home/ao9fd8p3td27/domains/phpbasics.brettmcsherry.com/html
[SITE_CGIROOT] => /home/ao9fd8p3td27/domains/phpbasics.brettmcsherry.com/html/cgi-bin
[SITE_HTMLROOT] => /home/ao9fd8p3td27/domains/phpbasics.brettmcsherry.com/html
[HTTPS] => on
[SSL_TLS_SNI] => www.phpbasics.brettmcsherry.com
[HTTP2] => on
[H2PUSH] => off
[H2_PUSH] => off
[H2_PUSHED] =>
[H2_PUSHED_ON] =>
[H2_STREAM_ID] => 1
[H2_STREAM_TAG] => 358343-397-1
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache
[SERVER_NAME] => www.phpbasics.brettmcsherry.com
[SERVER_ADDR] => 208.109.51.85
[SERVER_PORT] => 443
[REMOTE_ADDR] => 216.73.216.122
[DOCUMENT_ROOT] => /home/ao9fd8p3td27/domains/phpbasics.brettmcsherry.com/html
[REQUEST_SCHEME] => https
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => /home/ao9fd8p3td27/domains/phpbasics.brettmcsherry.com/html
[SERVER_ADMIN] => webmaster@phpbasics.brettmcsherry.com
[SCRIPT_FILENAME] => /home/ao9fd8p3td27/domains/phpbasics.brettmcsherry.com/html/arrays.php
[REMOTE_PORT] => 5703
[SERVER_PROTOCOL] => HTTP/2.0
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /arrays.php
[SCRIPT_NAME] => /arrays.php
[PHP_SELF] => /arrays.php
[REQUEST_TIME_FLOAT] => 1766917216.9541
[REQUEST_TIME] => 1766917216
)