PHP |从数组重新排序删除元素? [英] PHP | Remove element from array with reordering?

查看:130
本文介绍了PHP |从数组重新排序删除元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除一个数组的元素,并重新排列后,无需在阵列中的空元素?

 < PHP
   $ C =阵列(0 => 12,1 = GT; 32);
   未设置($ C [0]); //会扭曲阵列。
?>

答案/解决方案:阵列的array_values​​(阵列的$输入)

 < PHP
   $ C =阵列(0 => 12,1 = GT; 32);
   未设置($ C [0]);
   的print_r(array_values​​($ C));
   //将打印:数组清除
?>


解决方案

  array_values​​($ C)

将返回只值一个新的数组,线性索引。

How can I remove an element of an array, and reorder afterwards, without having an empty element in the array?

<?php
   $c = array( 0=>12,1=>32 );
   unset($c[0]); // will distort the array.
?>

Answer / Solution: array array_values ( array $input ).

<?php
   $c = array( 0=>12,1=>32 );
   unset($c[0]);
   print_r(array_values($c));
   // will print: the array cleared
?>

解决方案

array_values($c)

will return a new array with just the values, indexed linearly.

这篇关于PHP |从数组重新排序删除元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆