What is the meaning of "_="?
[]
means push - put the given argument as a new element on the end of the array. That means that $ACTIVITYGROUPS
is an array*.
$arr = array();
$arr[] = 1; // Put 1 in position 0
$arr[] = "a"; // Put "a" in position 1
$arr[] = array() // Put a new, empty array in position 2
As stated by the PHP docs, array_push
has the same effect as []
.
* If it's not an array, using []
will give you a syntax error:
Warning: Cannot use a scalar value as an array in test.php on line 4
In many languages the []
notation stands for an array.
Is the same as php's array_push()
: it pushes an element in the variable that has []
at the end.
If the variable is null, you can consider the square brackets like a declaration of an array.
The same notation of push applies to Javascript, for example. When using it like $var[] = 'a';
what happens is the same as array_push()
I was talking above. Just finds the next position in the array and adds there your value.
An array can be walked with for
, foreach
, while
, do while
and you can check it's contents with print_r()
or var_dump()
functions.