php数组问题
有数组1和数组2,我想把数组1的值作为key,数组2的值作为value,存在数组3中,有什么方法吗?
回复内容:
有数组1和数组2,我想把数组1的值作为key,数组2的值作为value,存在数组3中,有什么方法吗?
<?php $a1=array("a","b","c","d"); $a2=array("Cat","Dog","Horse","Cow"); print_r(array_combine($a1,$a2)); ?>
如果两个数组的个数一致且数组1和数组2的值相对应的话,直接用循环就可以搞定了吧。
下面是我测试用的代码,测试过没有问题的。
<code><?php $a = array('a', 'b', 'c', 'd'); $b = array('1', '2', '3', '4'); $c = array(); for($i=0,$l=count($b);$i<$l;$i++) { $c[$a[$i]] = $b[$i]; } print_r($c); ?> </code>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
