+ 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?
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.
+ 1
please make yourself used to use $data = ['one', 'two', 'three'] to define array.
0
We need variable for store dsta
0
to store the value