PHP多维数组数字格式返回A

问题描述

我对数组元素的数字格式有疑问。无论元素值如何,它总是返回一个“ A”字母。

var mymap = L.map('mapid').setView([51.505,-0.09],13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
    maxZoom: 19,attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(mymap);;
var popup = L.popup().setContent("")
var marker = L.marker([51.5,-0.09]).bindPopup(popup).addTo(mymap);
marker.setPopupContent('')

chart= new PieChart({
    "pie": {
        "innerRadius": 0
    },"container": "demo","data": [
        {
            "url": "https:\/\/zoomcharts.com\/data\/browsers-extended.json"
        }
    ],"toolbar": {
        "fullscreen": true,"enabled": true
    },"interaction": {
        "resizing": {
            "enabled": false
        }
    }
})
var htmltext = '<div>I am a standalone popup.</div> <hr><div id="test">loading chart</div>'
marker.on("click",onClick);
function onClick(e) {
  marker.setPopupContent(htmltext)
  var chart2 = new PieChart({
      "pie": {
          "innerRadius": 0
      },"container": "test","data": [
          {
              "url": "https:\/\/zoomcharts.com\/data\/browsers-extended.json"
          }
      ],"toolbar": {
          "fullscreen": true,"enabled": true
      },"interaction": {
          "resizing": {
              "enabled": false
          }
      }
  })
}

我要求使用地址#mapid { height: 500px; }获得该值 这是数组的一部分:

 <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
   integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
   crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
   integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
   crossorigin=""></script>   
<script src="https://cdn.zoomcharts-cloud.com/1/latest/zoomcharts.js"></script>

<div id="demo"> Loading Pie Chart</div>
 <div id="mapid"></div>

如果这很麻烦,我也在与此文件一起使用tcpdf。我需要在适当的字段中调用特定的数组元素并将其转换为:123 123,45数字格式。

此外,还需要将日期格式从yyyy-mm-dd更改为dd-mm-yyyy,并加上“ r”。在日期之后。

解决方法

您可以使用array_walk_recursive()遍历数组。在回调中,添加不同的检查以在每种情况下修改值。

array_walk_recursive($array,function (&$val) {
    // Format integers
    if (filter_var($val,FILTER_VALIDATE_INT)) {
        $val = number_format($val,2,',' ');
    // Format dates
    } elseif (preg_match('/^\d{4}-\d{2}-\d{2}$/',$val)) {
        $parts = explode('-',$val);
        $val = implode('-',array_reverse($parts));
    }
});

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...