What exactly do the array_keys and array_values functions do?
时间: 2023-11-27 09:49:17 浏览: 80
The `array_keys()` function in PHP returns all the keys of an array as a new array. It takes an array as an argument and returns an array of keys.
Example:
```php
$array = array('key1' => 'value1', 'key2' => 'value2');
$keys = array_keys($array);
print_r($keys);
```
Output:
```
Array
(
[0] => key1
[1] => key2
)
```
The `array_values()` function in PHP returns all the values of an array as a new array. It takes an array as an argument and returns an array of values.
Example:
```php
$array = array('key1' => 'value1', 'key2' => 'value2');
$values = array_values($array);
print_r($values);
```
Output:
```
Array
(
[0] => value1
[1] => value2
)
```
Both of these functions are useful for manipulating arrays in PHP.
阅读全文