phparrayssyntaxvariable-assignmentsquare-bracket

What does an assignment expression involving a variable ending in empty square braces mean?


What does the assignment in this loop do? I don't get the array notation in it.

foreach ($fieldvalues as $fieldvalue) {
    $insertvalues[] = $fieldvalue;
}

Solution

  • $insertvalues[] means insert a new item into the array, its a shortcut of array_push(). Its also preferred as it created lesser overhead whilst the PHP is working.

    Additional:

    For those who are unsure how the loop works.

    foreach($fieldvalues as $fieldvalue)
    

    every time the loop... loops, the value $fieldvalue becomes the next value a pointer is looking it in the array $fieldvalues - thus adding this to a new array `$insertvalues by means of the shortcut syntax mentioned above.