Functions to add and delete cells in php array

墨辰丷
Release: 2023-03-31 22:18:02
Original
3083 people have browsed it

This article mainly introduces the common functions of adding and deleting units in PHP arrays. Examples analyze the usage skills of array_push, array_pop, array_shift and array_unshift functions. Friends in need can refer to the following

Example analysis of this article Commonly used functions for adding and deleting units in PHP arrays.

The specific analysis is as follows:

<?php
header("Content-type:text/html;charset=utf-8");
$arr = array("a"=>"Horse","b"=>"Cat","c"=>"Dog");
array_push($arr,"hello","world");
//array_push将一个或多个单元压入到数组末尾
print_r($arr);
echo "<br />";

//array_pop():删除数组的最后一个单元
array_pop($arr);
print_r($arr);
echo "<br />";

//array_shift():删除数组的第一个单元
array_shift($arr);
print_r($arr);
echo "<br />";

//array_unshift():在数组开头添加一个或多个单元
array_unshift($arr,"Horse");
print_r($arr);
?>
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP implements directory traversal and deletion based on the dir class

php custom array variable stores time zone information around the world

php method to implement client-side and server-side uploading of images

The above is the detailed content of Functions to add and delete cells in php array. For more information, please follow other related articles on the PHP Chinese website!

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