// Assign variable by reference $tpl->assign_by_ref('myVar', $originalVar); // Update value within template {$myVar} = 'new value'; // Value of original variable is also updated echo $originalVar; // Output: new value
// Create an array to pass by reference $data = ['foo' => 'bar']; // Assign data to template $tpl->assign_by_ref('data', $data); // Update the value of 'foo' within the template {$data.foo} = 'baz'; // View changes outside of template var_dump($data); // Output: ['foo' => 'baz']These examples demonstrate how `assign_by_ref` can be used to update variables within a template and affect the original values of those variables outside of the template. This method is commonly used in package libraries such as Smarty, Twig, and Blade.