如何从PHP数组中取消设置数字索引元素?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何从PHP数组中取消设置数字索引元素?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1887字,纯文字阅读大概需要3分钟。
内容图文
![如何从PHP数组中取消设置数字索引元素?](/upload/InfoBanner/zyjiaocheng/747/3a5a4eaf5370414fbcd91a2edbb41c98.jpg)
我有一个数组的集合,它包含数字索引和非数字.我想取消设置所有数字索引.
我的阵列是这样的.
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数组中取消设置数字索引元素?全部内容,希望文章能够帮你解决如何从PHP数组中取消设置数字索引元素?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。