gpt4 book ai didi

php - 从数组 Php 中删除最后 4 个元素

转载 作者:行者123 更新时间:2023-12-04 12:01:27 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





What's the most efficient way to array_pop() the last n elements in an array?

(4 个回答)



How to remove the nth element from the end of an array

(5 个回答)


4 个月前关闭。




这是我的数组

$array=Array( 
[0] => hell
[1] => for
[2] => sale
[3] => for
[4] => sale
[5] => earth
[6] => 0
)

我想知道如何从 $array 中删除最后 4 个元素

我只是想从 $array 那里得到“ hell 出售”。有人知道吗?

最佳答案

你可以试试 array_splice .

Try this code snippet here

<?php
$array = Array(
0 => "hell",
1 => "for",
2 => "sale",
3 => "for",
4 => "sale",
5 => "earth",
6 => 0);
array_splice($array, count($array) - 4, 4);
print_r($array);

关于php - 从数组 Php 中删除最后 4 个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47130726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com