Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Variables and assignment

A dollar sign introduces a case-sensitive variable name.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

$name = $value; $alias =& $name;

A dollar sign introduces a case-sensitive variable name. Assignment of a scalar by value gives an independent binding, while =& makes two names refer to the same variable value. Unsetting one of those names removes that binding and leaves the other name usable.

$qty=3; $copy=$qty; $alias=&$qty; ++$alias; unset($alias); echo json_encode([$qty,$copy,isset($alias)]);
[4,3,false]

Examples

<?php
$qty=3; $copy=$qty; $alias=&$qty; ++$alias; unset($alias); echo json_encode([$qty,$copy,isset($alias)]);

Result

[4,3,false]

Sources