I have a php file where I saved all language string. This is the content:
function lang($phrase) { static $lang = array( 'step_one' => 'First step', 'step_two' => 'Second step', ... and so on ... ); return $lang[$phrase]; } Essentially, when I load a javascript file I want store all array index in a variable like this:
var Lang = <?php echo json_encode(lang()); ?>; this code line is inserted in a script, this script is available in a php file. Now before of execute this line I have imported the php file where all string translation is available. What I'm trying to achieve, is get all index of this array, in the variable Lang. Actually I can load a single string traduction from php like this:
lang('step_one'); but how I can save this array in javascript variable?
array_keyson the array if you just want all keys. php.net/array_keys<?php echo json_encode(lang(array_keys)); ?>;?array_keys.echo json_encode(array_keys(lang());You can check if$phraseis empty in your function and if so return the whole array (you should check the variable anyway to not raise any warnings).