Solved

dynamic variable name

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

920 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

18 Experts available now in Live!

Get 1:1 Help Now