扫码关注官方订阅号
在Python中有zip函数,例如:
a = [1, 1, 1] b = [2, 2, 2] zip(a, b) Out: [(1, 2), (1, 2), (1, 2)]
PHP如何快速实现呢
ringa_lee
可以用 array_map 快速实现:
array_map
$a = [1, 1, 1]; $b = [2, 2, 2]; $result = array_map(null, $a, $b); var_dump($result);
http://php.net/manual/zh/function.array-merge.php
function zip($a, $b) { return array_map(function($x, $y){ return [$x, $y]; }, $a, $b); }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
可以用
array_map
快速实现:http://php.net/manual/zh/function.array-merge.php