[Day 28] PHP array_column / array_keys / array_values

假设目前有阵列

$fruits = [
    ['id'=>0,'fruit'=>'apple','sweetness'=>2],
    ['id'=>1,'fruit'=>'banana','sweetness'=>4],
    ['id'=>2,'fruit'=>'grape','sweetness'=>5],
    ['id'=>3,'fruit'=>'orange','sweetness'=>1],
];

array_column

array_column(阵列变数, key名称(想取得的column的key) , 返回新阵列的key(可填可不填));

print_r(array_column($fruits,'fruit'));

https://ithelp.ithome.com.tw/upload/images/20211013/20142046cdoIPKalNV.png

print_r(array_column($fruits,'fruit','sweetness'));

https://ithelp.ithome.com.tw/upload/images/20211013/20142046SzEXB6nrF7.png

array_keys

取得阵列的key

print_r(array_keys($fruits[0]));

https://ithelp.ithome.com.tw/upload/images/20211013/20142046Gy61FYthyJ.png

print_r(array_keys($fruits));

https://ithelp.ithome.com.tw/upload/images/20211013/201420465FQ2vD5gBW.png

array_values

取得阵列的value

print_r(array_values($fruits));

https://ithelp.ithome.com.tw/upload/images/20211013/20142046xKs701rssw.png


<<:  Vaadin login with Facebook - day28

>>:  【领域展开 28 式】 auther box 文末笔者签名档设定与 Gravatar 认识

[Day13] 学 Reactstrap 就离 React 更近了 ~ Navbar ‧ 初识篇

前言 今天说好要来介绍 Navbar, 就是导览列,所以也是前端经常使用到的 Component。 ...

[ Day 38 ] - winston 记录下发生的错误

常见的故事 ... 客户 : 系统出错了 , 可以帮忙修一下吗 【・ヘ・?】 工程师 : 我这边看起...

Day#13 登入画面(2)

前言 昨天成功的放上imageView以及标题,今天来把其他的栏位放上~ 登入栏位 LoginVie...

DAY14 - [JS] 扩充toDoList功能 : 新增 category

今日文章目录: 需求说明 事前准备 需求说明 针对不同用途的toDoList。像是:工作用的toD...

DAY7-EXCEL统计分析:统计学是什麽?

在我们学习统计学之前应该清楚理解何谓统计学,这样才能够学以致用,并有效利用excel等工具来帮助我们...