在JavaScript中将PHP数组转换为JSON数组时,“,”成为数组的第一个元素

When i convert my PHP array into a JSON array the first element of the array is empty and it's ",". Here is my code:

var ctx = document.getElementById("myChart");
  var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
      labels: **<?php echo json_encode($d_dates);?>**,
      datasets: [{
      ......

I have checked the array in PHP is ok but when i convert it this occurs.

Here is the solution:

<?php echo json_encode(array_values(array_filter($d_dates)));?>

array_filter removes all empty elements in the array