using a variable as a part in another variabele, php.

Posted on 2005-04-15
Last Modified: 2006-11-18
I would like to make a variable using a piece of text and an already existing variable.

How can I make the variable, for instance, $picture01, out of $number='01' ?

Regards, Maurice van Ulden
Question by:mvulden
    LVL 33

    Accepted Solution

    $number = "01";
    $myNewVar = "picture" . $number;
    $$myNewVar = "A Good Value";
    echo $$myNewVar; // result: A Good Value
    echo $picture01; // result: A Good Value
    LVL 32

    Expert Comment

    My proposal:

     $number = '01';
     ${"picture$number"} = 'My Value';
     echo ${"picture$number"};
    LVL 33

    Expert Comment

    Of course, it looks like this might be better suited to an array.
    LVL 14

    Expert Comment

    No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
    I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: snoyes_jw {http:#13791960}

    Any objections should be posted here in the next 4 days. After that time, the question will be closed.

    EE Cleanup Volunteer

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to dynamically set the form action using jQuery.

    754 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

    20 Experts available now in Live!

    Get 1:1 Help Now