<?php
// declared in controller...
$data = [
'a' => -1.5,
'b' => false,
'c' => null,
'd' => 'stringy "string" thing',
'e' => range(3,10),
'f' => "0",
'g' => (object)['food' => 'bard'],
'h' => "not used",
];
// the CodeIgniter effect...
extract($data);
// in your view...
$portToJS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
echo "\n<script>\nlet ";
foreach ($portToJS as $i => $variable) {
echo (!$i ? '' : ",\n\t") , "{$variable} = " , json_encode(${$variable});
}
echo ";\n</script>";
preferences:
134.63 ms | 406 KiB | 5 Q