PHP学习笔记——数组
2022/1/15 11:04:23
本文主要是介绍PHP学习笔记——数组,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<?php // 在此之前的$addresses没有定义 echo $addresses[0]; // 无输出 echo $addresses; // 无输出 $addresses[0] = "100@100.com"; $addresses[1] = "111@111.com"; $addresses[2] = "222@222.com"; echo $addresses; $addresses = array("100@100.com","111@111.com","222@222.com"); echo $addresses; $price['apple'] = 1.00; $price['banana'] = 2.00; $price['oranger'] = 3.00; echo $price; $price = array( 'apple' => 1.00, 'banana' => 2.00, 'oranger' => 3.00 ); echo $price; $number = array(); /* 创建空数组 */ $color = array('Mike' => "black",'0' => "Brown",'1' => "Green"); /* 错误的代码,后面的键是从0开始的整数 */ $color = array('Mike' => "black","Brown","Green"); $family = array('Mike','Depp','Elliot'); $family[] = "Taylor"; /* $family[3]是"Taylor" */ $person = array('name' => "Niko"); $person[] = "S1mple"; /* $person[0] 是 "S1mple" */ $number = range(2, 5); /* $number = array(2, 3, 4, 5); */ $letters = range('a', 'z'); /* $letters 保存了字母表 */ $size = count($family); /* $size = 4 */ $scores = array(5, 10); $padded = array_pad($scores, 5, 0); /* $padded = array(5, 10, 0, 0, 0); */ $padded = array_pad($scores, -5, 1); /* $padded = array(1, 1, 1, 5, 10); */ $values = range('a','e'); list($m,$n,$o) = $values; /* $m = "a" , $n = "c" , $o = "e"; */ $order = array("Tom","Dick","Jack","Helen"); list($second,$third) = array_slice($order,1,2); /* $second = "Dick",$third = "Jack"; */ ?>
这篇关于PHP学习笔记——数组的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-19php8的协程和hyperf的协程有什么区别?-icode9专业技术文章分享
- 2024-12-19php8 的fiber是什么?-icode9专业技术文章分享
- 2024-12-05怎么在php8,1 里面开启 debug?-icode9专业技术文章分享
- 2024-12-05怎么在php8,1 里面开启 debug?-icode9专业技术文章分享
- 2024-11-29使用PHP 将ETH账户的资产汇集到一个账户
- 2024-11-23怎么实现安卓+php 热更新方案?-icode9专业技术文章分享
- 2024-11-22PHP 中怎么实现判断多个值是否为空、null 或者为 false?-icode9专业技术文章分享
- 2024-11-11开源 PHP 商城项目 CRMEB 二次开发和部署教程
- 2024-11-09怎么使用php在kaufland平台刊登商品?-icode9专业技术文章分享
- 2024-11-05PHP的抽象类和接口是什么,有什么区别-icode9专业技术文章分享