Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the ways of passing values of php variables?

Shulou Source: shulou.com Published: 2022-06-01 13:10:44 09月27日 Update

This article mainly introduces the ways of passing values of php variables. It is very detailed and has a certain reference value. Friends who are interested must finish reading it.

1. Value transfer

Description: "copy" the value of one variable and then assign it to another variable. There is no relationship between the two variables at this time.

Sample code:

/ / the value is passed $name = 'Zhang San'; $zs = $name;echo $name,$zs; / / Zhang San San $name ='Li Si'; / / the reassignment of the variable, overwriting the original value echo $name,$zs; / / Li Si Zhang San 2 with the current value. Reference transfer

Description: give the spatial address of the value of one variable to another. At this time, the two variables share a data space and point to the same address. At this time, the two variables are related.

Reference value passing property:

"if the way to pass a value by reference is to modify a variable, other variables will also change. If you delete one of them, the other will not be affected."

Sample code:

$age = 18 age; / / get the data address of the $age variable with the & symbol, & call the address symbol echo $age,$zsage; / / 18 18$ age = 20 echo echo $age,$zsage; / / 20 20unset ($age); echo $age,$zsage; / / error 20 is the whole content of this article "what are the ways of passing values of php variables"? thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Variable address Zhang San way two time code content data example space symbol article Li Si between value interest boy partner point to Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Linux Shulou Information Microsoft Apple