<?php /** * Created by PhpStorm. * User: Administrator * Date: 2022/4/20/020 * Time: 13:38 */ //数组 //直接赋值创建数组 echo"<pre>"; $sanguo=[['name'=>'liubei','yuwen'=>89,'shuxue'=>67], ['name'=>'gaunyu','yuwen'=>45,'shuxue'=>22], ['name'=>'zhangfei','yuwen'=>72,'shuxue'=>85], ['name'=>'caocao','yuwen'=>80,'shuxue'=>66], ]; print_r($sanguo); echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; //2.用函数创建数组 新课 $sanguo = array('liubei','guanyu','zhangfei'); print_r($sanguo); $shuihu=array(array('id'=>'01','name'=>'songjiang'),array('id'=>02)); print_r($shuihu); $xiyou = array('sunwukong','master'=>'tangsheng','zhubajie','shasen'); print_r($xiyou); echo rand(1000,9999); echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; //3.用range函数创建数组 $a=range('A','Z',5); print_r($a); $b=range(5,10); print_r($b); $v=($v); echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; //4.数组元素的追加 array_unshift() 追加的元素在数组开头 $city = array('henan'=>'zhengzhou','nanjing','hubei'=>'wuhan','changsha'); print_r($city); $n=array_unshift($city,'guangzhou','chengdu'); var_dump($city,$n); echo"<br>"; echo"<br>"; echo"<br>"; echo"<br>"; //5.数组元素的追加 追加的元素在数组后面 array push() //$city = array('henan'=>'zhengzhou','nanjing','hubei'=>'wuhan','changsha');) //print_r($city); //$n=array_unshift($city,'guangzhou','chengdu'); //var_dump($city,$n);