I'm trying to convert a PHP multidimensional array to a javascript array WITHOUT using json encoder because of the version of the server.
Exemple of a multidimensional Array :
Array (
[0] => Array (
[0] => 18
[1] => Région Grand EST
[2] => GE )
[1] => Array (
[0] => 17
[1] => Région Grand OUEST / NORD
[2] => GO N )
[2] => Array (
[0] => 25
[1] => Région Grand OUEST / SUD
[2] => GO S )
)
Currently for no multidimensional array i'm using this function :
function js_str($s) {
return '"' . addcslashes($s, "\0..\37\"\\") . '"';
}
function js_array($array) {
if (is_array($array)) {
$temp = array_map('js_str', $array);
return '[' . implode(',', $temp) . ']';
}
return '[-1]';
}
But i can't use it for multidimensional, i'm trying to do somthing similar recursively to do it with any size of array.
To get a result like :
myArray = [[18, 'Région Grand EST', 'GE'],[17, 'Grand OUEST / NORD', 'GO N'], [25, 'Région Grand OUEST / SUD', 'GO S']];
It's really hard to find an answer without json_encode, thanks for your help. (Yes i'm developping on a prehistoric server)