<?php
$student = array("张三","李四","王五","赵六","孙七","陈八");
//取数组长度
len = count(student);
echo $len;
echo $student[0]."<br>";
//修改元素$student[1] = "玉玉";
print_r($student);
echo "<br>";
//删除最后一个array_pop($student);
print_r($student);
//随机取值index= array_rand(student);
echo "<br>";
echo student\[index];
echo "<br>";
/*或者index = rand(0,count(student)-1);
echo "<br>";
echo student\[index];
*/ //数组去重$score = array("10","20","30","40","20","30","40");
print_r($score);
new_arry = array_unique(score);
echo "<br>";
print_r($new_arry);
echo "<br>";
//数组遍历for (i=0;i<count(student);i++){
echo student\[i]."<br>";
}
//关联数组$student_1 = array('name'=>'张三','id'=>'1','addr'=>'北京');
$student_2 = array('name'=>'李四','id'=>'2','addr'=>'上海');
$student_3 = array('name'=>'呜呜','id'=>'2','addr'=>'成都');
echo "<br>"; $student_1['name'] = "哈哈";
//遍历数组的value//或者使用 array_values end()取最后一个
foreach($student_1 as $stu){
echo $stu; echo "<br>";
}
//遍历数组key array_key_last()
keys = array_keys(student_1);
foreach($keys as $key){ echo $key."-----";
echo student_1\[key]; echo"<br>"; }
//字符串转数组$source = 'taobao.com.cn.net.edu';
myarray = explode('.',source);
echo "<br>"."----";
print_r($myarray);
//数组转字符串 $grade = array(1,2,3,4,5,6,7,8,9);
string_gradre = implode(',',grade); print_r(($string_gradre));
?>
PHP基础
都适、隶仁ミ2024-06-12 2:04
相关推荐
tjjingpan2 分钟前
在国产电脑上运行PDFSAM软件使用pdf分割合并交替混合处理pdf文档重整旗鼓~4 分钟前
2.flask中使用装饰器统一验证用户登录杜小白也想的美11 分钟前
FlaskAPI-路径参数、查询参数EterNity_TiMe_13 分钟前
【论文复现】农作物病害分类(Web端实现)hope_wisdom22 分钟前
Linux系统编程之目录遍历bohu8327 分钟前
sentinel学习笔记8-系统自适应与黑白名单限流香橙薄荷心32 分钟前
学一学前沿开发语言之Python潜意识起点32 分钟前
Java数组:静态初始化与动态初始化详解KevinRay_33 分钟前
Numpy指南:解锁Python多维数组与矩阵运算(下)anddddoooo37 分钟前
Kerberoasting 离线爆破攻击