string question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BlueOrbits
Forum Newbie
Posts: 4
Joined: Fri Jan 05, 2007 2:39 pm

string question

Post by BlueOrbits »

Hi

I have this code :

Code: Select all

<?PHP
$a = 'df';

$b_df = 'Woow';

print $b_$a;
?>
How could I get the string : $b_$a ?? it must equal to $b_df
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Take a look at http://www.php.net/manual/en/language.v ... riable.php or (even better) use arrays instead.

Code: Select all

$a = 'df';
$b = array('df'=>'Woow');
print $b[$a];
BlueOrbits
Forum Newbie
Posts: 4
Joined: Fri Jan 05, 2007 2:39 pm

Post by BlueOrbits »

is there anyway to do it without array ?
james.aimonetti
Forum Newbie
Posts: 6
Joined: Tue Jan 30, 2007 10:44 pm

Post by james.aimonetti »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php
    $a = 'df';
    $b_df = 'Woow';

    print ${'b_' . $a};
?>
What you need this for, I have no idea. But see http://www.php.net/manual/en/language.v ... riable.php for how to do variable variables.


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
$a = 'bc';
$d_bc = 'Woow';

echo $d_{$a};
?>
Untested, but i should work.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

is there anyway to do it without array ?
Arrays are the easiest and most sensible option.
BlueOrbits
Forum Newbie
Posts: 4
Joined: Fri Jan 05, 2007 2:39 pm

Post by BlueOrbits »

Everah wrote:

Code: Select all

<?php
$a = 'bc';
$d_bc = 'Woow';

echo $d_{$a};
?>
Untested, but i should work.
I tried that before, it doesn't work
BlueOrbits
Forum Newbie
Posts: 4
Joined: Fri Jan 05, 2007 2:39 pm

Post by BlueOrbits »

james.aimonetti wrote:Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php
    $a = 'df';
    $b_df = 'Woow';

    print ${'b_' . $a};
?>
What you need this for, I have no idea. But see http://www.php.net/manual/en/language.v ... riable.php for how to do variable variables.


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color][/quote]

many thanks bro.

it works 100%
Post Reply