What is the method for replacing array key names in php

王林
Release: 2023-03-06 20:54:02
Original
2081 people have browsed it

PHP array key name replacement method: You can create a new array by merging two arrays using the array_combine() function, where one array element is the key name and the other array element is the key value.

What is the method for replacing array key names in php

array_combine() function creates a new array by merging two arrays, where the elements of one array are key names and the elements of the other array are key values. , returns the merged array. If the two arrays have different numbers of elements, return FALSE.

(Recommended graphic tutorial: php video tutorial)

Note: The number of elements in the key name array and the key value array must be the same!

Grammar:

array_combine(keys,values);
Copy after login

Example:

<?php
$fname=array("Peter","Ben","Joe");
$age=array("35","37","43");

$c=array_combine($fname,$age);
print_r($c);
?>
Copy after login

Related recommendations: php training

The above is the detailed content of What is the method for replacing array key names 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!