dongxin5054 2015-11-11 15:38
浏览 119
已采纳

显示数组中所有元素的数据类型

I have an array

array:23 [▼
  "cpe_mac" => "204492519985"
  "bandwidth_max_up" => 30000
  "bandwidth_max_down" => 50000
  "filter_icmp_inbound" => true
  "dmz_enabled" => false
  "dmz_host" => "http:\/\/ddd.com"
  "vlan_id" => 2
  "dns" => array:2 [▶]
  "xdns_mode" => 0
  "cfprofileid" => 11111
  "stub_response" => 0
  "acl_mode" => 1
  "portal_url" => "http:\/\/portal.com"
  "fullbandwidth_max_up" => 1000000
  "fullbandwidth_max_down" => 2000000
  "fullbandwidth_guaranty_up" => 300000
  "fullbandwidth_guaranty_down" => 400000
  "account_id" => 1000
  "location_id" => 3333
  "network_count" => 3
  "group_name" => "test_group"
  "vse_id" => 20
  "firewall_enabled" => false
]

I want to know the data type of each one of them, so I did this

$cpe_type = [];
foreach ($cpe as $k => $v) {
    $cpe_type[$k] = gettype($v);
}

I got as what I wanted

array:23 [▼
  "cpe_mac" => "string"
  "bandwidth_max_up" => "integer"
  "bandwidth_max_down" => "integer"
  "filter_icmp_inbound" => "boolean"
  "dmz_enabled" => "boolean"
  "dmz_host" => "string"
  "vlan_id" => "integer"
  "dns" => "array"
  "xdns_mode" => "integer"
  "cfprofileid" => "integer"
  "stub_response" => "integer"
  "acl_mode" => "integer"
  "portal_url" => "string"
  "fullbandwidth_max_up" => "integer"
  "fullbandwidth_max_down" => "integer"
  "fullbandwidth_guaranty_up" => "integer"
  "fullbandwidth_guaranty_down" => "integer"
  "account_id" => "integer"
  "location_id" => "integer"
  "network_count" => "integer"
  "group_name" => "string"
  "vse_id" => "integer"
  "firewall_enabled" => "boolean"
]

Is there any pre-made PHP functions that can provide me similar functionality?

  • 写回答

3条回答 默认 最新

  • duanbin198788 2015-11-11 15:40
    关注

    You can use array_map:

    var_dump(array_map('gettype', $array));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器