Array
(
[Carriers] => Array
(
[Carrier] => Array
(
[0] => Array
(
[carriersid] => a2e01423-2e8f-4458-8c13-2bfd08591d75
[phonenumber] => 1234567890
[network] => CELLCO PARTNERSHIP DBA VERIZON WIRELESS - CA
[wireless] => True
[zipcode] => 92675
[city] => Capistrano Valley
[price] => 3.0000
[createddate] => 2016-02-19 06:18:56
)
我想将[carrierid]资本化为Carriersid。 我知道array_change_key_case函数在那里,但它只能使键成为UPPERCASE或LOWERCASE。 任何帮助深表感谢。 :)
答案 0 :(得分:2)
尝试这个,它将成为第一个字母大写
<?php
$arr = ['asd'=> '123', 'sdf' => '444'];
$data = [];
foreach ($arr as $key => $val) {
$data[ucfirst($key)] = $val;
}
print_r($data);
?>
答案 1 :(得分:2)
以下是可能的解决方案,如果您想要这样的CarrieSid然后使用以下,否则使用Rahul发布的代码 -
$carrier_arr = $arr['Carriers']['Carrier'];
$final_arr = array();
for($i=0;$i<count($carrier_arr);$i++){
$final_arr[$i]['Carriersid'] = $carrier_arr[$i]['carriersid'];
$final_arr[$i]['Phonenumber'] = $carrier_arr[$i]['phonenumber'];
$final_arr[$i]['Network'] = $carrier_arr[$i]['network'];
$final_arr[$i]['Wireless'] = $carrier_arr[$i]['wireless'];
$final_arr[$i]['Zipcode'] = $carrier_arr[$i]['zipcode'];
$final_arr[$i]['City'] = $arr[$i]['city'];
$final_arr[$i]['Price'] = $carrier_arr[$i]['price'];
$final_arr[$i]['Createddate'] = $carrier_arr[$i]['createddate'];
}
答案 2 :(得分:1)
这有助于您更改数组首字母大写的键
<?php
foreach ($arr as $key => &$val) {
$val = ucfirst($val);
}
?>