Ticker

6/recent/ticker-posts

Php superglobals

<span>Photo by <a href="https://unsplash.com/@maselkowski?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Peter Masełkowski</a> on <a href="https://unsplash.com/s/photos/php-superglobals?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>



Superglobals means variables that are predefined variables in PHP which means that are always accessible. Below are some examples of the PHP superglobals variables.
The PHP superglobal variables are:
  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION

$GLOBALS

$GLOBALS is a PHP superglobal variable that is used to access global variables from anywhere in the PHP script.
PHP stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable.
The example:-

<?php
$x = 75;
$y = 25;
function addition() {
    $GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y'];
}
addition();
echo $z;
?>


output are:-100

 Hope you like this post...In the next post, I will explain all the remaining PHP superglobals variables.

Post a Comment

0 Comments