Break Copy By Reference

Posted on 2009-04-16
Last Modified: 2012-05-06
How do I create a copy of the original from a reference.

$A = 1;
$B =& $A;
$C = $B;

How do I ensure $C is not a reference to $A, but a copy of $A.
Question by:nbcit
    LVL 39

    Accepted Solution

    You are allready doing that:
    $A = 1;
    $B =& $A;
    $C = $B;
    $A = 2;
    echo $C;  # outputs '1'
    $A = 1;
    $B =& $A;
    $C =& $B;
    $A = 2;
    echo $C;  # outputs '2'

    Open in new window

    LVL 8

    Assisted Solution

    Here is a good explanation of references... it may help answer your question.

    Author Comment

    You are right, I hadn't made a copy of it before using it. Thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now