I want to avoid writing to DB and use constants/array for lang files etc.
i.e:
$lang = array (
'hello' => 'hello world!'
);
and be able to edit it from the back office. (then instead of fetching it from the poor db, i would just use $lang['hello']..).
what are you suggesting for the best and efficient way to pull it of?
We can create an array and use print_r() function to return the array and use the fwrite() function to write the array to the file. The print_r() function takes the array to be printed and the boolean value as the parameters. Use the fopen() function to create a file file. txt with w as the second parameter.
Since the size of the data is fixed, one simple way of writing this entire array into a file is using the binary writing mode: FILE *f = fopen("client. data", "wb"); fwrite(clientdata, sizeof(char), sizeof(clientdata), f); fclose(f);
Let us see how to save a numpy array to a text file. Creating a text file using the in-built open() function and then converting the array into string and writing it into the text file using the write() function. Finally closing the file using close() function.
the most efficient way i found looks like this:
build up your array in php somehow and export it into a file using var_export()
file_put_contents( '/some/file/data.php', '<?php return '.var_export( $data_array, true ).";\n" );
then later, wherever you need this data pull it like this
$data = include '/some/file/data.php';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With