PHP Interview questions


Total available count: 33
Subject - PHP Frameworks
Subsubject - PHP

What is the difference between global vs $GLOBALS?

Global: all references to variable will refer to the global version. There is no limit to the number of global variables that can be modified by a function.

Example:

<?php
$x = 1;
$y = 2;

function Sum()
{
global $x, $y;

$y = $x + $y;
}

Sum();
echo $y;
?>

$GLOBALS: References to all variables available in global scope. An associative array contains references to all variables which are currently described in the global scope of the script. The variable names are the keys of the array.

Example:

<?php
function test() {
$foo = "local variables";

echo '$foo in global scope: ' . $GLOBALS["foo"] . "\n";
echo '$foo in current scope: ' . $foo . "\n";
}

$foo = "Example Info";
test();
?>

 




Next 5 interview question(s)

1
What is Void?
2
What is the difference between gettype() vs str replace?
3
What is NaN?
4
PHP supports 8 primitive types. What are they?
5
What are the differences between echo and print in PHP?