Quick question with some WordPress functions:
$options = (array)get_options('value');
Doing so allows me to get an array. But how does it work?
Thanks in advance.
PHP is a loosely typed language and assigns types to variables depending what is assigned to it and its concept is used to change the current data type of variable from one date type to another.
$foo = 'Hello World';
var_dump(is_string($foo));//true
$bar = (array) $foo;
echo $bar[0];// no doubt string offset also can be access using $foo[offset]
var_dump(is_array($bar));// true
$foo = 'a string'; if ($foo) it does convert string into booleanIt is a type casting , PHP has really good documentation for this
Type casting in PHP works much as it does in C: the name of the desired type is written in parentheses before the variable which is to be cast.
<?php
$foo = 10; // $foo is an integer
$bar = (boolean) $foo; // $bar is a boolean
?>
get_options()returns an object (probably STDClass). You get an array with indices as properties of the object.