मान लीजिए हमारे पास निम्न मान है:
$nextValue = 100;
आइए एक नया चर लें और रेफरेंस असाइन करें:
$currentValue = &$nextValue;
रेफरेंस असाइन करने के लिए, PHP में रेफरेंस असाइनमेंट ऑपरेटर यानी =&$anyVariableName का उपयोग करें।
उदाहरण
<!DOCTYPE html> <html> <body> <?php $nextValue = 100; $currentValue = &$nextValue; echo "Next Value=" . $nextValue . "<br>"; echo "Current Value=" . $currentValue . "<br>"; $nextValue = 45000; echo "After changing the value of next will reflect the current value because of =&" . "<br>"; echo "Next Value=" . $nextValue . "<br>"; echo "Current Value=" . $currentValue; ?> </body> </html>
आउटपुट
Next Value=100 Current Value=100 After changing the value of next will reflect the current value because of => Next Value=45000 Current Value=45000
व्याख्या: =& ऑपरेटर एक रेफरेंस बनाता है, कॉपी नहीं। दोनों चर एक ही मेमोरी लोकेशन को इंगित करते हैं। एक को बदलने से दूसरा भी बदल जाता है।
उपयोग के मामले: बड़े डेटा को कॉपी किए बिना पास करना, फ़ंक्शन में मूल चर को संशोधित करना।