Home > Backend Development > PHP Problem > How to remove array subscript in php

How to remove array subscript in php

王林
Release: 2023-03-01 08:44:01
Original
5358 people have browsed it

How to remove array subscript in php

Purpose:

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

Convert the above array into the following format:

$arr = array('value1','value2','value3')
Copy after login

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);
Copy after login

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!

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