Home > Backend Development > PHP Problem > How to use php to only have the values ​​of the array and not the keys?

How to use php to only have the values ​​of the array and not the keys?

藏色散人
Release: 2023-03-13 18:20:02
Original
2388 people have browsed it

php How to implement as long as the array value does not require keys: 1. Create a PHP sample file; 2. Define an array; 3. Pass "while ($fruit = current($fruits)) {...] " method to get the value of the array without keys.

How to use php to only have the values ​​of the array and not the keys?

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

php How to only need the value of the array without the key ?

Get the current array value current()

The current() function returns the array value at the current pointer position in the array. Its form is as follows:

mixed current(array array)
Copy after login

Let’s modify the previous example. This time we want to get the array value:

$fruits = array("apple"=>"red", "banana"=>"yellow");
while ($fruit = current($fruits)) {
   printf("%s <br />", $fruit);
   next($fruits);
}
// red 
// yellow
Copy after login

Related introduction:
current() function returns the value of the current element in the array .

Each array has an internal pointer pointing to its "current" element, which initially points to the first element inserted into the array.

Tip: This function does not move the internal pointer of the array.

Related methods:

end() - Point the internal pointer to the last element in the array and output it.

next() - Sets the internal pointer to the next element in the array and outputs it.

prev() - Sets the internal pointer to the previous element in the array and outputs it.

reset() - Set the internal pointer to the first element in the array and output it.

each() - Returns the key name and key value of the current element and moves the internal pointer forward.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to use php to only have the values ​​of the array and not the keys?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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