
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP Unsetting References
Introduction
It is possible to break binding between the content and variable by using unset() function. The unset() function doesn't destroy the content but only decouples variable from it.
Example
<?php $a=10; $b=&$a; echo "before unsetting : ", $a, " " ,$b, PHP_EOL; unset($b); echo "after unsetting :" . $a . " "; $b=20; echo $b; ?>
Output
After unsetting, $b can be used as normal vaiable
before unsetting : 10 10 after unsetting : 10 20
Reference can also be removed by assigning variable to NULL
Example
<?php $x=100; $y=&$y; echo "x and y are references ", $x, " " ,$y, PHP_EOL; $y=NULL; $x=200; echo "x: ", $x . " y: " ,$y, PHP_EOL; ?>
Output
Result of above script is as follows
x and y are references 100 x: 200 y:
Advertisements