I’ve been reviewing a sample code to learn PHP and what I saw made me confused in the following code:
$in = $_REQUEST;
require_once 'utils.php';
require_once 'utils_user.php';
require_once 'utils_email.php';
require_once 'utils_affiliate.php';
#Load Settings
$globalSettings = parse_ini_file("settings.ini", true);
if(isInDevelMode())
{
$system = "devel";
}
if(strlen($in{'system'} > 0))
{
$system = strip_tags($in{'system'});
}
Here a variable called $in was created and $_REQUEST was assigned to it and then later on in the second if-statement it was written like if(strlen($in{'system'} > 0)) and I don’t quite understand what $in{'system'} here. It doesn’t look like an array but $_REQUEST is an array-like to retrieve its content. Can somebody tell me what these curly braces are used for after $in variable…
Thanks.
The curly braces can be used to access array keys instead of the square ones.
The syntax is exactly the same with the only difference that curly brackets can’t be used for pushing values:
This alternative syntax was originally intended for use when accessing string offsets. But now it is just an old, obsolete syntax, which is likely to be deprecated. (Actually it already was deprecated some time while PHP 5.3 was developed.)