Sie versuchen, wann ein PHP-Array-Variable in json_encode JavaScript-Variable ein Problem hat:Key Ordnung, wenn json_encode PHP-Variable (Array) in JavaScript-Variable
var duration_options = <?=json_encode($duration_options)?>;
var duration_options_items = '';
$.each(duration_options,function(index, value) {
if(init_act_duration == value){
var selected_option = 'selected=selected';
}else{
var selected_option = '';
}
duration_options_items = duration_options_items + '<option value="'+index+'" '+selected_option+'>'+value+'</option>';
});
duration_options_items = '<select class="form-control select2 select_ajax select_ajax_duration" name="edit_activity_duration" style="width:100%">'+duration_options_items+'</select>';
Der PHP-Array ist
Array
(
[0.5] => 0.5
[1] => 1
[1.5] => 1.5
[2] => 2
[2.5] => 2.5
[3] => 3
[3.5] => 3.5
[4] => 4
)
Nach json_encode wenn ich das json in meinem JavaScript verwenden, das Array ist wie:
Array
(
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[0.5] => 0.5
[1.5] => 1.5
[2.5] => 2.5
[3.5] => 3.5
)
Nur kann es nicht verstehen, wh y und habe keine Ahnung, wie man sie richtig bestellt
_After json_encode wird: ..._ Ist das wirklich ein Javascript-Array? – hindmost
überprüfen Sie dies: - https://eval.in/557376. Es besagt eindeutig, dass Sie etwas mit Ihrem Array vor 'json_encode' tun –
Bitte bearbeiten Sie die Frage und posten Sie Ihren Code. Nimm nicht einfach an, dass PHP kaputt ist ;-) –