Reputation: 3072
I need to combine a $variable with a underscore and word like this:
$agent = agent id word is "declined."
$newvar = $agent_declined;
How can i do that?
Upvotes: 1
Views: 2484
Reputation: 545
Try this:
${$variableName.'_declined'} = 'foo';
For more info, see PHP: Variable variables
Upvotes: 1
Reputation: 16269
Use the concatenation:
<?php
$newvar = $agent . "_declined";
?>
Read here!
Upvotes: 3
Reputation: 13331
Like this: $newvar = $agent . "_declined";
In PHP, you combine strings by using .
Upvotes: 3
Reputation: 57728
Like this?
$agent_declined = "foobar";
$id = "declined";
$varname = "\$agent_" . $id
$newvar = $$varname; // should give foobar
I would advise against the use of double $$
, it's confusing.
Upvotes: 1