Page 1 of 1
string question
Posted: Fri Feb 09, 2007 9:49 am
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
Posted: Fri Feb 09, 2007 9:56 am
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];
Posted: Fri Feb 09, 2007 10:08 am
by BlueOrbits
is there anyway to do it without array ?
Posted: Fri Feb 09, 2007 2:20 pm
by james.aimonetti
Everah | Please use 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
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]
Posted: Fri Feb 09, 2007 2:31 pm
by RobertGonzalez
Code: Select all
<?php
$a = 'bc';
$d_bc = 'Woow';
echo $d_{$a};
?>
Untested, but i should work.
Posted: Fri Feb 09, 2007 3:54 pm
by Ollie Saunders
is there anyway to do it without array ?
Arrays are the easiest and most sensible option.
Posted: Fri Feb 09, 2007 5:18 pm
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
Posted: Fri Feb 09, 2007 5:19 pm
by BlueOrbits
james.aimonetti wrote:Everah | Please use 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
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%