是什么在PHP的最简单的方法来从两个平行索引数组的关联数组? [英] What's the most straightforward way in PHP to create an associative array from two parallel indexed arrays?

查看:68
本文介绍了是什么在PHP的最简单的方法来从两个平行索引数组的关联数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于以下两个索引数组:

Given the following two indexed arrays:

$a = array('a', 'b', 'c');
$b = array('red', 'blue', 'green');

什么是产生如下关联数组最简单明了/有效的方式:

What is the most straighforward/efficient way to produce the following associative array?:

$result_i_want = array('a' => 'red', 'b' => 'blue', 'c' => 'green');

感谢。

推荐答案

array_combine

在您的情况:

$result_i_want = array_combine($a, $b);

这篇关于是什么在PHP的最简单的方法来从两个平行索引数组的关联数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆