php数组取消索引,如何从PHP数组中取消设置数字索引元素?

我有一个数组的集合,它包含数字索引和非数字.我想取消设置所有数字索引.

我的阵列是这样的.

Array

(

[554] => Array

(

[0] => 554

[1] => Jiaqi Zheng

[2] => Female

[3] => 28

[4] => Table Tennis

[5] =>

[6] =>

[7] =>

[8] =>

[rank] => 554

[athlet_name] => Jiaqi Zheng

[gender] => Female

[sport] => Table Tennis

)

[555] => Array

(

[0] => 555

[1] => Zach Ziemek

[2] => Male

[3] => 23

[4] => Athletics

[5] =>

[6] =>

[7] =>

[8] =>

[rank] => 555

[athlet_name] => Zach Ziemek

[gender] => Male

[sport] => Athletics

)

)

在这里,我必须取消设置所有的数字索引.

我这样使用unset,它对我来说很好.

unset(

$history_years_wise_country_wise_details_arr[ $history_years_wise_country_wise_details_info[0]][0],

$history_years_wise_country_wise_details_arr[$history_years_wise_country_wise_details_info[0]][1],

$history_years_wise_country_wise_details_arr[$history_years_wise_country_wise_details_info[0]][2],

$history_years_wise_country_wise_details_arr[$history_years_wise_country_wise_details_info[0]][3],

$history_years_wise_country_wise_details_arr[$history_years_wise_country_wise_details_info[0]][4],

$history_years_wise_country_wise_details_arr[$history_years_wise_country_wise_details_info[0]][5],

$history_years_wise_country_wise_details_arr[$history_years_wise_country_wise_details_info[0]][6],

$history_years_wise_country_wise_details_arr[$history_years_wise_country_wise_details_info[0]][7],

$history_years_wise_country_wise_details_arr[$history_years_wise_country_wise_details_info[0]][8]

);

有什么办法可以减少代码行吗?这里0到8是一个系列.

我可以在一行代码中取消设置所有索引,因为它们都是数字的吗?

是否可以使用正则表达式?

我想要类似的东西

unset(

$history_years_wise_country_wise_details_arr[ $history_years_wise_country_wise_details_info[0]][anything_which_will_take_index_from_0_to_8]);

有什么建议?

谢谢

解决方法:

您可以使用带有is_string()函数的array_filter()作为其回调函数:

$array = array_filter($array, 'is_string', ARRAY_FILTER_USE_KEY);

标签:php,arrays

来源: https://codeday.me/bug/20190727/1549252.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值