I want a dynamic property name like this:
$_taxVocabName = 'name';
$node->field_ . $_taxVocabName;
This should call:
$node->field_name
How can I do this?
I could not find anything on php.net or elsewhere.
Thanks Sascha
I want a dynamic property name like this:
$_taxVocabName = 'name';
$node->field_ . $_taxVocabName;
This should call:
$node->field_name
How can I do this?
I could not find anything on php.net or elsewhere.
Thanks Sascha
Two ways:
First, use a variable:
$property = 'field_' . $_taxVocabName;
$node->$property;
Second, use curly brackets:
$node->{'field_' . $_taxVocabName};
I'd think a much better way to do this would be
$taxVocabName = "name";
$property = "field_" . $taxVocabName;
Then you would have to set the variable to a value of course...
like so:
$$property = "My variable variable";
or:
$field_name = "My variable variable";
I know it's a bit later, but maybe this will help someone else down the road.