当前位置:网站首页>PHP 如何把二维数组变为 一维数组
PHP 如何把二维数组变为 一维数组
2022-07-15 16:49:00 【自己收藏学习】
1.array_column($array, column_key,index_key); 返回数组中某一个单一列的值。
这个方法 得益于 PHP 内部的使用方法 array_column($array,column_key,index_key) 版本 5.5 +
array 必需。规定要使用的多维数组(记录集)。
column_key :必需。需要返回值的列。
可以是索引数组的列的整数索引,或者是关联数组的列的字符串键值。
该参数也可以是 NULL,此时将返回整个数组(配合 index_key 参数来重置数组键的时候,非常有用)。
index_key :可选。用作返回数组的索引 / 键的列
2.两个数组大小相等的数组 合并 成为一个数组 一个数组的键(value) 成为新数组的 key
通过合并两个数组来创建一个新数组,其中的一个数组元素为键名,另一个数组元素为键值: 5.4 +
这个方法 得益于 PHP 内部的使用方法 array_combine(keys,values)
$arr = [
['id' => 1001, 'name' => 'gsj1'],
['id' => 1002, 'name' => 'gsj2'],
['id' => 1003, 'name' => 'gsj3'],
];
//php如何将二维数组变为一维数组
$tempArr = array_column($arr, 'name', 'id');
echo "<pre>";
print_r($tempArr);
打印出来为
Array ( [1001] => gsj1 [1002] => gsj2 [1003] => gsj3 )
边栏推荐
- 复杂链表的复制
- IDEA类文档注释模板设置
- Timesformer: can you understand video by transformer alone? Another attack of attention mechanism
- urllib.error.URLError: <urlopen error [Errno 11004] getaddrinfo failed>
- 唐门暗器之私有云排名
- 2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(9)思路
- Cron表达式使用
- C语言 第十章 指针
- Exploration of yolact model structure
- Tips for setting dropout parameters
猜你喜欢

MySQL-pymysql模块

C语言 第九章 字符串

H264 decoding sequence display sequence reference sequence

基于TaskScheduler和CronTask实现动态增删启停定时任务功能

初学者怎么快速学会SQL

oracle怎样转义单引号

About some string related functions, memory functions and some simulations

PD QC诱骗取电应用IC《乐得瑞LDR6328S》广泛应用于各大小家电

60 year old developer's suggestion, try to change it!

PD QC decoy power application IC "liderui ldr6328s" is widely used in all sizes of household appliances
随机推荐
Design and implementation of fingertip Roulette Games (uniapp implements wechat applet)
compileflow 淘宝工作流引擎
php 生成excel表的2种方法
Asymmetric encryption RSA and symmetric encryption AES project application
select/poll/epoll的区别
示波器使用概念记录
Thumbnail image processing class library
Idea class document annotation template settings
OTA 升级中的跟文件系统切换
Chapter 7 preprocessing of C language
Resnet50 structure diagram
Latest idea reset method
数据库存IP地址,用什么数据类型
How Oracle escapes single quotation marks
PD QC decoy power application IC "liderui ldr6328s" is widely used in all sizes of household appliances
Compileflow Taobao Workflow Engine
Swin transformer, the best paper model of iccv 2021, finally started video
markdown学习笔记 第二章 基本语法 (markdown编辑器下显示)
Excel import / export annotation General Edition
oracle怎样转义单引号