2020年3月25日
<?php
$b = [
123 => '十进制',
0xFF => '十六进制',
077 => '8进制',
0b111 => '2进制',
'08' => '字符串',
3.33 => '浮点数',
'0b111' => '字符串的二进制',
'077' => '字符串的8进制',
//布尔值
true => 'true',
false => 'false',
//null
null => 'null',
];
echo "<pre>";
var_dump($b);
echo"</pre>";
$arr1 = array(
10,
20,
30,
40,
50,
60,
70,
80,
90,
);
echo"<pre>";
var_dump($arr1);
echo"</pre>";
echo"<hr>";
echo"手动输出:";
echo"<br>";
echo $arr1[0],"<br>";
echo $arr1[1],"<br>";
echo $arr1[2],"<br>";
echo $arr1[3],"<br>";
echo $arr1[4],"<br>";
echo $arr1[5],"<br>";
echo $arr1[6],"<br>";
echo $arr1[7],"<br>";
echo $arr1[8],"<br>";
echo $arr1[9],"<br>";
echo"总长度:",count($arr1);
echo"<hr>";
echo"自动输出:";
echo"<br>";
for ($i=0;$i <count($arr1);$i++){
echo $arr1[$i],"<br>";
}
$a = array(1,2,3,4,5,8,9,150);
var_dump($a);
echo"<hr>";
foreach($a as $b){
echo$b ,"<br>";
}
echo"<hr>";
$arr =[
'name' => 'tim',
'age' => 18,
'like' => 'geme'
];
foreach($arr as $caa =>$cod){
echo $caa,'=>',$cod,"<br>";
}
php2
<?php
$b = [
123 => '十进制',
0xFF => '十六进制',
077 => '8进制',
0b111 => '2进制',
'08' => '字符串',
3.33 => '浮点数',
'0b111' => '字符串的二进制',
'077' => '字符串的8进制',
//布尔值
true => 'true',
false => 'false',
//null
null => 'null',
];
echo "<pre>";
var_dump($b);
echo"</pre>";
$arr1 = array(
10,
20,
30,
40,
50,
60,
70,
80,
90,
);
echo"<pre>";
var_dump($arr1);
echo"</pre>";
echo"<hr>";
echo"手动输出:";
echo"<br>";
echo $arr1[0],"<br>";
echo $arr1[1],"<br>";
echo $arr1[2],"<br>";
echo $arr1[3],"<br>";
echo $arr1[4],"<br>";
echo $arr1[5],"<br>";
echo $arr1[6],"<br>";
echo $arr1[7],"<br>";
echo $arr1[8],"<br>";
echo $arr1[9],"<br>";
echo"总长度:",count($arr1);
echo"<hr>";
echo"自动输出:";
echo"<br>";
for ($i=0;$i <count($arr1);$i++){
echo $arr1[$i],"<br>";
}
$a = array(1,2,3,4,5,8,9,150);
var_dump($a);
echo"<hr>";
foreach($a as $b){
echo$b ,"<br>";
}
echo"<hr>";
$arr =[
'name' => 'tim',
'age' => 18,
'like' => 'geme'
];
foreach($arr as $caa =>$cod){
echo $caa,'=>',$cod,"<br>";
}
php3
<?php
$b = [
123 => '十进制',
0xFF => '十六进制',
077 => '8进制',
0b111 => '2进制',
'08' => '字符串',
3.33 => '浮点数',
'0b111' => '字符串的二进制',
'077' => '字符串的8进制',
//布尔值
true => 'true',
false => 'false',
//null
null => 'null',
];
echo "<pre>";
var_dump($b);
echo"</pre>";
$arr1 = array(
10,
20,
30,
40,
50,
60,
70,
80,
90,
);
echo"<pre>";
var_dump($arr1);
echo"</pre>";
echo"<hr>";
echo"手动输出:";
echo"<br>";
echo $arr1[0],"<br>";
echo $arr1[1],"<br>";
echo $arr1[2],"<br>";
echo $arr1[3],"<br>";
echo $arr1[4],"<br>";
echo $arr1[5],"<br>";
echo $arr1[6],"<br>";
echo $arr1[7],"<br>";
echo $arr1[8],"<br>";
echo $arr1[9],"<br>";
echo"总长度:",count($arr1);
echo"<hr>";
echo"自动输出:";
echo"<br>";
for ($i=0;$i <count($arr1);$i++){
echo $arr1[$i],"<br>";
}
$a = array(1,2,3,4,5,8,9,150);
var_dump($a);
echo"<hr>";
foreach($a as $b){
echo$b ,"<br>";
}
echo"<hr>";
$arr =[
'name' => 'tim',
'age' => 18,
'like' => 'geme'
];
foreach($arr as $caa =>$cod){
echo $caa,'=>',$cod,"<br>";
}
笔记:
数组下标的强制转换
下标只出现两种类型:int string
如果16进制数:会被自动转换为10进制来作为下标;
所以合法整型表达方式都会转换为10进制,如果超出进制取值则会报错;
定义为字符串则可以使用;浮数点的小数部分会被删除,然后直接使用删除后的整数作为键
布尔值会转换为整数然后作为键
null作为键则表达为一个空字符串
数组和对象不能作为数组的键名使用会报错
字符串的值如果用整数来表达也是同样意思,那就转换为整数作为下标,反正则不转换
for循环遍历数组
计次循环0-9 只能循环索引数组,而且必须是连续性的数组
使用for循环输出数组中的所有内容
【】里面可以写变量,其中中括号里面可以写表达式
获取数组内内容:$变量名【索引】
这时for循环可以循环一个指定范围的数字
刚好和索引数组的键对应
$i =0;0<9 true;$a[$i ] => $a[0]
$i ++1;1<9 true;$a[$i ] => $a[1]
….
$++ 9;9<9 false;
foreach遍历:
foreach($数组 as $值变量){
echo”输出”;
}
循环,$v变量等于遍历出来的值;
第一遍时$v就等于一个值;
第二遍时$v就等于二个值;
第n遍时$v就等于n个值;
索引不连续也可以遍历(循环)输出
foreach 可以遍历关联数组