Seen in functions where $a
is a function parameter:
if(!is_array($a))
$a=[$a]
I just don't know what this means,
Thanks!
It means;
if
$a
is not an array, then create$a
as anarray
and use the contents (value) of$a
as the first element of the newly created array called $a.
In readable English emulating a Code, this could mean:
<?php
if($a IS NOT AN ARRAY):
THEN CREATE A NEW VARIABLE $a OF TYPE: ARRAY.
TAKE WHATEVER IS INSIDE THE INITIAL $a VARIABLE...
AND PUT IT AS THE FIRST ELEMENT OF THE OVERRIDDEN, NEW $a VARIABLE.
endif;
This code convert $a from some non-array data-type to array data-type
if(!is_array($a)) \\check whether $a is not an array
$a=[$a] \\change $a to an array with only one element which was previously stored in $a
It takes a simple variable and turns it into an array.
[$a]
is shorthand for array($a)
.
If $a
is not an array, [$a]
turns it into an array.