- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the meaning and usage of ‘=&’ assignment operator in PHP?
Instead of copying the data from one variable to another one, the changes made to an array or object can be made to another using the ‘=&’ operator. This is known as the ‘assignment by reference’ method, which means both the values or objects will point to the same data, and no copies of the data are made. This way, data redundancy is avoided.
<?php $my_val1 = 67; $my_val2 = &$my_val1; $my_val1 = 89; print "The value is : "; print "$my_val2"; ?>
The value is : 89
Inside the <php> tags, two values are declared wherein the second value is the assignment by reference of the first value. Next, the value of the first variable is changed and the second value is displayed. It displays the most recently updated value of the first object. This means the changes made to the first variable have reflected in the second variable without making any copies.
- What is an assignment operator in C#?
- Reference assignment operator in PHP to assign a reference?
- What is vertical bar in Python bitwise assignment operator?
- Explain the concept of logical and assignment operator in C language
- What's the difference between assignment operator and copy constructor in C++?
- Java Assignment Operator Examples
- Difference Between Copy Constructor and Assignment Operator in C++
- Copy constructor vs assignment operator in C++