Another quick way not mentioned here:
So add a header with <?php start, variable name \$my_array = with \$my_array = \$ and footer ?> End tag.
Now you can use include() like any other valid php script.
// storing $file = '/tmp/out.php'; file_put_contents($file, "<?php\n\$my_array = ".var_export($var, true).";\n?>"); // retrieving as included script include($file); //testing print_r($my_array);
out.php will look like this
<?php $my_array = array ( 'a'=>1, 'b'=>2, 'c'=>3, 'd'=>4, 'e'=>5 ); ?>
MTK Feb 18 '18 at 9:12 2018-02-18 09:12
source share