I have a loop that goes from 1 to 10 and prints values in
$entity_object->field_question_1
through 10 so...
$entity_object->field_question_1
, $entity_object->field_question_2
, etc
And I want to print this in this loop, how can I get the variable? I tried doing the
$var = "entity_object->field_question_".$i; print $$var;
But that did not work...
How can I get these values?
All variables in PHP start with a $ sign, followed by the name of the variable. A variable name must start with a letter or the underscore character _ . A variable name cannot start with a number. A variable name in PHP can only contain alpha-numeric characters and underscores ( A-z , 0-9 , and _ ).
A variable name must start with a letter or the underscore character. A variable name cannot start with a number. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive ( $age and $AGE are two different variables)
Description. Variable is a symbol or name that stands for a value. Variables are used for storing values such as numeric values, characters, character strings, or memory addresses so that they can be used in any part of the program. Declaring PHP variables.
PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL. Assume we have an HTML page that contains a hyperlink with parameters: <html> <body>
This should work:
$var="field_question_$i"; $entity_object->$var;
Actually you need to take the variable outside the string like this in order to those solutions to work: $var="field_question_".$i;
$entity_object->$var;
Or
$entity_object->{"field_question_".$i}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With