Global variable is just like any other variable but the difference is that this scope is global in application. Lets discuss some important points for the global variable in order to use them inside the application see below; In PHP we use an array to access this global variable. Adding Options To Option List Page Attribute Undefined Array Key under PHP 8; Fixed: Multilingual copy site tree with alias . A Computer Science portal for geeks. PHP has three types of variable scopes: Local variable Global variable Static variable Local variable The variables that are declared within a function are called local variables for that function. How to declare a custom attribute in HTML ? Undefined variable problem with PHP function This is because you're using the $pera variable (which exists only in the global scope) inside a function. Variable (computer science) In computer programming, a variable is an abstract storage location paired with an associated symbolic name, which contains some known or unknown quantity of information referred to as a value; or in simpler terms, a variable is a named container for a particular set of bits or type of data (like integer, float . Undefined variable: mysqli - SemicolonWorld Ad Blocker Detected! How to execute PHP code using command line ? To check whether a variable has been set (ie. How to declare the optional function parameters in JavaScript ? Is this an at-all realistic configuration for a DHC-2 Beaver? We just need to follow some standards while accessing them inside the function. For $y, either you skip that output by checking isset($y) or else assign a default value at the global scope. Kieron Pollard and Rashid Khan will take over the captain's duties for MI Emirates and MI Cape Town, respectively. $demovar1= "Hello "; The error can be avoided by using the isset () function.This function will check whether the variable is set or not. But once defined we are directly using them without the global keyword. How to declare object with computed property name in JavaScript ? To access the variable directly from the array we have to use $GLOBALS keyword followed by the variable name like we access an array by its index. You have to learn the scope of a variable in PHP. Are you calling this from within a function?