How many ways are there to assign values to variables in php?
3 ways to assign values to variables in php
1. Value assignment, such as $a=1,$b=$a, etc.;
2. Reference assignment, for example $a=&$b, that is, $a and $b both point to the same storage variable value address in memory;
3. Reference counting value transfer, The default value-passing method for objects in php and js is reference counting. The example is as follows:
<?php class Dog{ public $name="小花"; public $leg=4; } $a=new Dog;//此时,$a指向了内存中的一个地址(假设0XFFAD[1]),该地址又指向最终对象的值 $b=$a;//此时,$b和$a都指向了内存中的另一个地址(0XFFAD[2]),该地址又指向最终对象的值 var_dump($b->leg);//结果是int 4 $b=999; var_dump($b);//结果是int 999; var_dump($a);//此时的结果不是int 999,而是object(Dog)[1] public 'name' => string '灏忚姳' (length=6) public 'leg' => int 4
It can be seen that the object's value-passing method is somewhat different from the second reference-counting method. difference.
Recommended: "PHP Tutorial"
The above is the detailed content of There are several ways to assign values to variables in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
