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 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算