• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

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

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
0
mvulden
Asked:
mvulden
  • 2
1 Solution
 
snoyes_jwCommented:
$number = "01";
$myNewVar = "picture" . $number;
$$myNewVar = "A Good Value";
echo $$myNewVar; // result: A Good Value
echo $picture01; // result: A Good Value
0
 
ldbkuttyCommented:
My proposal:

<?php
 $number = '01';
 ${"picture$number"} = 'My Value';
 echo ${"picture$number"};
?>
0
 
snoyes_jwCommented:
Of course, it looks like this might be better suited to an array.
0
 
hujiCommented:
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.

Huji
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now