Solved

dynamic variable name

Posted on 2013-01-18
3
267 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
Comment Utility
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
Comment Utility
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
Comment Utility
Perfect. Many thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

763 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

10 Experts available now in Live!

Get 1:1 Help Now