is possible to do this in php? $code->Info_.$code

I was looking at several locations, but does not like looking, I want to perform this operation

$tpl = new Savant3();
$tpl->Info_.$db_code["name"] = $db_code["info"];

php echo $this->eprint($this->Info_Name);

is it possible?. Thank you.


You can simply do

$tpl->{"Info_$db_code[name]"} = $db_code["info"];

see also the manual for this:

Yes, completely doable using variable variables. Use a variable containing the function name to access the class function. Consider this:

class testClass {
  function randomstring() {
    return 'hello world!';

And this:

$test = new testClass();

// simulate an arbitrary second half of a string/function name
$random_string = 'string';

// build class name into single variable using arbitrary first half
// of string/function name
$class_name = 'random' . $random_string ;
// use that variable (variable variable)
echo $test->{$class_name}(); // hello world!

In your case: If this is a class property, you'd do this: (if it's a function, add the ())

$prop_name = 'Info_' . $db_code["name"];
$tpl->{$prop_name} = $db_code["info"];

Need Your Help

Getting Resource from strings

java android string concat

I've got many resources with names based on a pattern:

How to use viewbox when height of svg is dynamically changing

javascript svg viewbox

I have a resizable div. It has two inner divs. One of the inner divs has an svg element in it.