Home > Backend Development > PHP Problem > How to remove the first two items of an array in php

How to remove the first two items of an array in php

青灯夜游
Release: 2023-03-15 13:58:01
Original
2466 people have browsed it

php method to remove the first two items of the array: 1. Use the array_splice() function to intercept all elements of the array starting from subscript 2. The syntax is "array_splice($arr,2)"; 2. Use array_slice() function, syntax "array_slice($arr,2)".

How to remove the first two items of an array in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php before removing the array Two items

Method 1: Use the array_splice() function

When the array_splice() function deletes some elements of the array, these will be The deleted elements are formed into a new array, and the new array is returned; therefore the array_splice() function can be used to intercept array fragments.

<?php
header("Content-type:text/html;charset=utf-8");
$arr = array(10,12,20,25,24,22);
echo "原数组:";
var_dump($arr); 

echo "去掉数组前2项后的元素片段:";
$result = array_splice($arr,2); //去掉数组前2位的元素
var_dump($result);
?>
Copy after login

How to remove the first two items of an array in php

Method 2: Use array_slice() function

array_slice() function is one provided by PHP to intercept arrays Function that extracts a fragment from an array.

<?php
header("Content-type:text/html;charset=utf-8");
$arr = array(10,12,20,25,24,22);
echo "原数组:";
var_dump($arr); 

echo "去掉数组前2项后的元素片段:";
$result = array_slice($arr,2); //截取数组前2位的元素
var_dump($result);
?>
Copy after login

How to remove the first two items of an array in php

Recommended learning: "PHP Video Tutorial", "PHP ARRAY"

The above is the detailed content of How to remove the first two items of an array in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template