Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Assignation

Assignation, sometimes misspelled assignement, refers to the process of assigning a value to a variable. It is a fundamental concept in programming that allows storing and manipulating data.

The main operator of assignation is =. There are secondary operators, such as +=, *=, ??=, … which are called short assignation: they apply a specific operation while assigning.

Finally, there are some inherent assignations: foreach() loops, method calls and list() operator perform assignations without an explicit operator.

<?php

    $a = 'b';
    
    // $c is assigned by 
    foreach([1, 2, 3] as $c) {}
    echo $c; // $c is 3
    
    // list call that assigns values
    [$a, $b, $c] = ['a', 'b', 'C'];

?>

Documentation

See Also