Let's say I have a table
[table fruits]
--------+------------+
ID [PK] | fruit |
--------+------------+
1 | Orange |
2 | Banana |
3 | Coconut |
and I need to save a list of IDs and names in a JS array, like for example:
var fkOptionList = [[1]['Orange'],[2]['Banana'],[3]['Coconut']]
in PHP I achieved this by:
$fkOptionTableR = $fkOptionTableQ->result_array();
$fkOption2dArray[] = array();
$i = 0;
$j = 0;
foreach ($fkOptionTableR as $array) {
foreach ($array as $row) {
$fkOption2dArray[$i][$j] = $row;
$j++;
}
$i++;
$j = 0;
}
which results in (according to var_dump):
array(3) {
[0]=> array(2) { [0]=> string(1) "1" [1]=> string(6) "Orange" }
[1]=> array(2) { [0]=> string(1) "2" [1]=> string(6) "Banana" }
[2]=> array(2) { [0]=> string(1) "3" [1]=> string(7) "Coconut" }
}
I would need that array in my JS script, but the problem is it's in other file (above PHP script is loaded once by a CI's controller). Is there a way to pass it?
fkOptionListis a syntax error.fkOptionList = [[1, 'Orange'],[2, 'Banana'],[3, 'Coconut']]