Home  >  Article  >  Backend Development  >  PHP tips: Exchange the keys and values ​​of the array to form a new array, find the value and get the key_PHP tutorial

PHP tips: Exchange the keys and values ​​of the array to form a new array, find the value and get the key_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:29:38923browse

Copy code The code is as follows:

$cityname = array_flip($city_DB[name]); //Exchange the keys and values ​​of the array A new array is formed
$city_name = array_search($city_id,$cityname,true); //Find the value and get the key

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323421.htmlTechArticleCopy the code The code is as follows: $cityname = array_flip($city_DB[name]); //Add the keys of the array to The value exchange forms a new array $city_name = array_search($city_id,$cityname,true); //The search value is...
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