Solved

dynamic variable name

Posted on 2013-01-18
3
270 Views
Last Modified: 2013-01-18
I want my variable name to be dynamic variable. See my code below...

$media_brand_listed . $row_rs_ocg_brands2['brand_name'] = "Yes";

Open in new window


i.e. Say $row_rs_ocg_brands2['brand_name'] equals HP I want the variable name to be...

$media_brand_listedHP = "Yes";

What I have done is wrong. How should I do it?
0
Comment
Question by:petewinter
3 Comments
 
LVL 11

Accepted Solution

by:
Slimshaneey earned 300 total points
ID: 38792510
You can use variable variables like this

$var  = 'media_brand_listed' . $row_rs_ocg_brands2['brand_name'] ;

$$var = 'Yes';

The $$ is a variable variable.

Now you can call $media_brand_listedHP and get the result 'Yes'
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
ID: 38792522
I agree with above.
you could do it in a single line:
${media_brand_listed' . $row_rs_ocg_brands2['brand_name'] } = 'Yes'; 

Open in new window

0
 

Author Closing Comment

by:petewinter
ID: 38792549
Perfect. Many thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

830 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