Home  >  Article  >  Backend Development  >  How to remove array subscript in php

How to remove array subscript in php

王林
王林Original
2020-05-19 11:34:365202browse

How to remove array subscript in php

Purpose:

$arr = array('key1'=>'value1','key2'=>'value2','key3'=>'value3')

Convert the above array into the following format:

$arr = array('value1','value2','value3')

The solution is as follows:

You can use array_values( ) method to achieve.

array_values() function returns an array containing all the values ​​in the array.

Tip: The returned array will use numeric keys, starting from 0 and increasing by 1.

The specific code is as follows:

$arr = array('key1'=>'value1','key2'=>'value2','key3'=>'value3');
$arr2 = array_values($arr);
print_r($arr2);

For more related tutorials, please visit php Chinese website.

The above is the detailed content of How to remove array subscript in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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