what does $a=[$a] mean in PHP?

Jackson

Seen in functions where $a is a function parameter:

if(!is_array($a))
    $a=[$a]

I just don't know what this means,

Thanks!

Poiz

It means;

if $a is not an array, then create $a as an array 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;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related