Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How php deletes the I th element of an array

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to delete the I element of the array by php". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to delete the I element of the array by php" can help you solve the problem.

In php, you can use the array_splice () function to delete the I element of an array, which can delete a specified number of elements from a specified location; the syntax for deleting the I element of an array is "array_splice ($arr,i-1,1);".

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

In php, you can use the array_splice () function to delete the I th element of the array.

Example:

There is an array like this:

Delete the second element of the array

Echo "delete the second element of the array:"; array_splice ($arr,1,1); var_dump ($arr)

Delete the third element of the array

Echo "delete the third element of the array:"; array_splice ($arr,2,1); var_dump ($arr)

Delete the second and third elements of the array

Array_splice ($arr,1,2); var_dump ($arr)

Description:

The array_splice () function is used to delete some elements of the array; you can delete it directly or replace it with other values.

The syntax of array_splice () is as follows:

Array array_splice (array & $arr, int $start [, int $length = 0 [, mixed $replacement]])

Parameter description:

Arr represents an array.

Start indicates where to start the deletion (subscript):

If start is positive, it is deleted from after going.

If the start is negative, it is deleted from back to front, starting from the end of the arr-start. For example,-2 means starting with the penultimate element of the array.

Length is an optional parameter that indicates the number of elements deleted:

If length is positive, it means deleting length elements

If length is negative, all elements from start to the reciprocal length at the end of the array will be deleted

If omitted, all elements from start to the end of the array are deleted.

Replacement is an optional parameter that represents the value to replace. If replacement has more than one value, it needs to be set to an array, and if there is only one value, it can not be set to an array.

If the result of the combination of start and length is that no elements are deleted, then the value contained in replacement will be inserted at the location specified by start.

Note that replacing array elements with replacement does not retain the original key name.

Return value: returns an array of deleted elements.

This is the end of the introduction to "how php deletes the first element of an array". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report