php method to remove array key values: 1. Use the "array_keys($array)" statement to remove all key values and return an array containing all key names; 2. Use "array_splice($array,$ start,$length)" statement can remove one or more key values at the specified position.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
There are many ways to remove array key values in php , two methods are introduced below:
Method 1: Use array_keys() function
array_key() function can get some or all key names in the array.
Use the array_key() function to remove all key values from the array and return a new array containing all key names.
Usage syntax:
array_keys($array)
Example:
<?php header("Content-type:text/html;charset=utf-8"); $arr=array("Name"=>"Peter","Age"=>"41","Country"=>"USA"); var_dump($arr); $keys=array_keys($arr); var_dump($keys); ?>
##Method 2: Use array_splice() function
array_slice() function is used to intercept an array, that is, to extract a fragment from the arrayUsage syntax:array_splice($array,$start,$length)Parameters:
- array represents the array to be intercepted. start indicates the starting position (subscript) of interception:
- If start is a positive number, interception is performed from front to back.
- If start is a negative number, start from the position -start from the end of arr and intercept from back to front. For example -2 means start from the second to last element of the array.
length is an optional parameter, indicating the intercepted length: - If length is a positive number, it indicates the number of intercepted elements;
- If length If it is a negative number, then the intercepted fragment will end at the length position from the end of the array;
- If it is omitted, it will start from the start position and continue to the end of the array.
<?php header("Content-type:text/html;charset=utf-8"); $arr=array(10,12,20,25,24); echo "原数组:"; var_dump($arr); echo "删除后的数组:" ; array_splice($arr,2); var_dump($arr); ?>
<?php header("Content-type:text/html;charset=utf-8"); $arr=array(10,12,20,25,24); echo "原数组:"; var_dump($arr); echo "删除后的数组:" ; array_splice($arr,2,-1); var_dump($arr); ?>
PHP Video Tutorial"
The above is the detailed content of How to remove array key value in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
