PHP array introductory tutorial array_values() function

WBOY
Release: 2016-07-25 08:57:56
Original
1243 people have browsed it
This article introduces the usage of the array_values() function of the PHP array operation function. Friends in need can refer to it.

In the php array function, the array_values() function returns all the values ​​in an array and automatically provides a numerical index for the returned array.

The form is as follows: array array_values(array array)

Example, get the value of each element found in $fruits:

<?php
//获取数组中各元素的值
//by bbs.it-home.org
$fruits["apple"] = "red";  
$fruits["banana"] = "yellow";  
$fruits["watermelon"]="green";  
$values = array_values($fruits);  
print_r($values);  
  
//Array ( [0] => red [1] => yellow [2] => green )  
?>
Copy after login

Sometimes you need to expand an array or delete a part of the array. PHP provides some functions for expanding and shrinking arrays. These functions provide convenience for programmers who wish to emulate various queue implementations (FIFO, LIFO). As the name suggests, the function names of these functions (push, pop, shift, and unshift) clearly reflect their functions.

Tips: A traditional queue is a data structure in which elements are deleted in the same order as elements are added, which is called first-in-first-out, or FIFO. In contrast, a stack is another data structure in which elements are removed in the reverse order in which they were added. This becomes last-in-first-out, or LIFO.



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