Hướng dẫn array_values() trong php

  • Trang chủ
  • Phát triển web
  • PHP
  • Hàm array_values() trong PHP

Hướng dẫn cách sử dụng hàm array_values() về mảng trong lập trình PHP

Tác dụng của hàm array_values()

The array_values() function returns an array containing all the values of an array.

The returned array will be indexed numerically, starting with 0 and increase each time by 1.

The following table summarizes the technical details of this function.

Return Value:Returns an indexed array of all the values of an array.
Version:PHP 4+


Syntax

The basic syntax of the array_values() function is given with:

The following example shows the array_values() function in action.

"apple", "b"=>"ball", "c"=>"cat", "d"=>"dog");

// Getting all the values from alphabets array
$result = array_values($alphabets);
print_r($result);
?>


Parameters

The array_values() function accepts the following parameters.

ParameterDescription
array Required. Specifies the array to work on.


More Examples

Here're some more examples showing how array_values() function actually works:

This function may ignore the numeric indexes, let's try out an example and see how it works:

10, 3=>25, 1=>50, 2=>75);

// Adding a value to the numbers array at index 0
$numbers[0] = 100;

// Getting all the values from numbers array
$result = array_values($numbers);
print_r($result);
?>

Bài viết này đã giúp ích cho bạn?

Bài viết mới