1   "/> 1   ">
Home > Backend Development > PHP Tutorial > php数组剔除元素后重新索引

php数组剔除元素后重新索引

WBOY
Release: 2016-06-13 13:12:18
Original
827 people have browsed it

php数组删除元素后重新索引
请问大家 知道php数组删除某个元素后 有提供重新索引的方法吗?
$tmp = array(1,2,3);
unset($tmp["1"]);
echo "

";<br>print_r($tmp);<br><br><br>运行结果:<br>Array<br>(<br>     [0] => 1<br>     [2] => 3<br>)<br><br>而我需要的结果是:<br>Array<br>(<br>     [0] => 1<br>     [1] => 3<br>)<br><br><br><br><br>请问php有没有提供这个函数 重新索引  跪谢!<br><br><font color="#e78608">------解决方案--------------------</font><br>
array_values()
<br><font color="#e78608">------解决方案--------------------</font><br>print_r(array_values($tmp));
<br><font color="#e78608">------解决方案--------------------</font><br>array_values() 函数返回一个包含给定数组中所有键值的数组,但不保留键名 <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template