Why do I need to use variable variable? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why do I need to use variable variable?

i can do these (echo $hello;) with out the other variable. I don't get the application of variable variable?

26th Jul 2016, 8:05 PM
Moses
4 Answers
+ 2
In some PHP framework with MVC implementation, when we try to send data from Controller to View, we will pass the data through array and we can access the data by call variable with array key name, for example (can't be run) : // In controller // Data student and teacher $data_student = 'Student name'; $data_teacher = 'Teacher name'; // Set it into $data $data = array( 'student' => $data_student, 'teacher' => $data_teacher ); // Process for passing $data to view $controller->view_and_pass_data( $data ); // Then, we can access data student and teacher easily from view by calling key of array $data echo $student; // Not $data['student'] echo $teacher; // Not $data['teacher'] I think in the background of view process, the key array are converted into variables based on key name using "variable variable" technique.
28th Jul 2016, 2:03 PM
Ayub Narwidian Adiputra
Ayub Narwidian Adiputra - avatar
+ 1
please make yourself used to use $data = ['one', 'two', 'three'] to define array.
29th Jul 2016, 9:51 AM
Dodol Didil
Dodol Didil - avatar
0
We need variable for store dsta
29th Jan 2017, 10:59 AM
Manish Rajput
Manish Rajput - avatar
0
to store the value
24th Feb 2017, 4:29 PM
Pratik Bobade
Pratik Bobade - avatar