2

Seen in functions where $a is a function parameter:

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

I just don't know what this means,

Thanks!

Jackson
  • 264
  • 2
  • 9

3 Answers3

4

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;
Poiz
  • 7,519
  • 2
  • 13
  • 17
2

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
bugwheels94
  • 28,872
  • 3
  • 36
  • 59
1

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.

Martin
  • 20,858
  • 7
  • 60
  • 113
colonelclick
  • 2,096
  • 2
  • 22
  • 30