I'm trying to pass a php array to javascript, but the array has non-sequential keys.
Here is a portion of the array:
Array
(
[1812] => Array
(
[RecID] => 1
[team_num] => 20
[player_id] => 1812
[name] => Brady, Tom
[id] => 1812
[tm_abbr] => NE
[tm_id] => 9003
[pos] => QB
[active] => 1
[ListOrder] => 1
[lg_pos] => QB
[NFL_pos] => QB
[data_type] => off
[fa_sort_category] => 1
[lineup_elig_pos] => Array
(
[1] => RB1
[2] => RB2
[3] => R1
[4] => R2
[5] => R3
)
)
[15574] => Array
(
[RecID] => 1
[team_num] => 20
[player_id] => 15574
[name] => Goff, Jared
[id] => 15574
[tm_abbr] => LAR
[tm_id] => 9025
[pos] => QB
[active] => 1
[ListOrder] => 1
[lg_pos] => QB
[NFL_pos] => QB
[data_type] => off
[fa_sort_category] => 1
[lineup_elig_pos] => Array
(
[1] => RB1
[2] => RB2
[3] => R1
[4] => R2
[5] => R3
)
)
[16381] => Array
(
[RecID] => 1
[team_num] => 20
[player_id] => 16381
[name] => Jackson, Lamar
[id] => 16381
[tm_abbr] => BAL
[tm_id] => 9030
[pos] => QB
[active] => 1
[ListOrder] => 1
[lg_pos] => QB
[NFL_pos] => QB
[data_type] => off
[fa_sort_category] => 1
[lineup_elig_pos] => Array
(
[1] => RB1
[2] => RB2
[3] => R1
[4] => R2
[5] => R3
)
)
I have tried this:
var roster = {};
roster = "<?php echo json_encode($roster, true); ?>";
But I get an error "Uncaught SyntaxError: Unexpected number"
The key is important to match the player id so I can reference it later in the code easily.