• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • 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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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