Solved

dynamic variable name

Posted on 2013-01-18
3
269 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 142

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

Gigs: Get Your Project Delivered by an Expert

Select from 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.

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…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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