<?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
相关推荐
船长@Quant几秒前
PyTorch量化进阶教程:第六章 模型部署与生产化叫我王富贵i14 分钟前
0基础入门scrapy 框架,获取豆瓣top250存入mysql爱写代码的小朋友15 分钟前
华三交换机配置常用命令wangjun515934 分钟前
jenkins 参数化发布到服务器 publish over ssh、label、Parameterized publishing熬夜造bug36 分钟前
LeetCode Hot100 刷题笔记(6)—— 栈、堆巷北夜未央37 分钟前
Python每日一题(13)愚润求学42 分钟前
【Linux】Linux权限半句唐诗44 分钟前
设计与实现高性能安全TOKEN系统低头不见1 小时前
一个服务器算分布式吗,分布式需要几个服务器小爬虫程序猿1 小时前
利用 PHP 爬虫按关键字搜索淘宝商品