2020年3月25日

    1. <?php
    2. $b = [
    3. 123 => '十进制',
    4. 0xFF => '十六进制',
    5. 077 => '8进制',
    6. 0b111 => '2进制',
    7. '08' => '字符串',
    8. 3.33 => '浮点数',
    9. '0b111' => '字符串的二进制',
    10. '077' => '字符串的8进制',
    11. //布尔值
    12. true => 'true',
    13. false => 'false',
    14. //null
    15. null => 'null',
    16. ];
    17. echo "<pre>";
    18. var_dump($b);
    19. echo"</pre>";
    20. $arr1 = array(
    21. 10,
    22. 20,
    23. 30,
    24. 40,
    25. 50,
    26. 60,
    27. 70,
    28. 80,
    29. 90,
    30. );
    31. echo"<pre>";
    32. var_dump($arr1);
    33. echo"</pre>";
    34. echo"<hr>";
    35. echo"手动输出:";
    36. echo"<br>";
    37. echo $arr1[0],"<br>";
    38. echo $arr1[1],"<br>";
    39. echo $arr1[2],"<br>";
    40. echo $arr1[3],"<br>";
    41. echo $arr1[4],"<br>";
    42. echo $arr1[5],"<br>";
    43. echo $arr1[6],"<br>";
    44. echo $arr1[7],"<br>";
    45. echo $arr1[8],"<br>";
    46. echo $arr1[9],"<br>";
    47. echo"总长度:",count($arr1);
    48. echo"<hr>";
    49. echo"自动输出:";
    50. echo"<br>";
    51. for ($i=0;$i <count($arr1);$i++){
    52. echo $arr1[$i],"<br>";
    53. }
    54. $a = array(1,2,3,4,5,8,9,150);
    55. var_dump($a);
    56. echo"<hr>";
    57. foreach($a as $b){
    58. echo$b ,"<br>";
    59. }
    60. echo"<hr>";
    61. $arr =[
    62. 'name' => 'tim',
    63. 'age' => 18,
    64. 'like' => 'geme'
    65. ];
    66. foreach($arr as $caa =>$cod){
    67. echo $caa,'=>',$cod,"<br>";
    68. }
    69. php2
    70. <?php
    71. $b = [
    72. 123 => '十进制',
    73. 0xFF => '十六进制',
    74. 077 => '8进制',
    75. 0b111 => '2进制',
    76. '08' => '字符串',
    77. 3.33 => '浮点数',
    78. '0b111' => '字符串的二进制',
    79. '077' => '字符串的8进制',
    80. //布尔值
    81. true => 'true',
    82. false => 'false',
    83. //null
    84. null => 'null',
    85. ];
    86. echo "<pre>";
    87. var_dump($b);
    88. echo"</pre>";
    89. $arr1 = array(
    90. 10,
    91. 20,
    92. 30,
    93. 40,
    94. 50,
    95. 60,
    96. 70,
    97. 80,
    98. 90,
    99. );
    100. echo"<pre>";
    101. var_dump($arr1);
    102. echo"</pre>";
    103. echo"<hr>";
    104. echo"手动输出:";
    105. echo"<br>";
    106. echo $arr1[0],"<br>";
    107. echo $arr1[1],"<br>";
    108. echo $arr1[2],"<br>";
    109. echo $arr1[3],"<br>";
    110. echo $arr1[4],"<br>";
    111. echo $arr1[5],"<br>";
    112. echo $arr1[6],"<br>";
    113. echo $arr1[7],"<br>";
    114. echo $arr1[8],"<br>";
    115. echo $arr1[9],"<br>";
    116. echo"总长度:",count($arr1);
    117. echo"<hr>";
    118. echo"自动输出:";
    119. echo"<br>";
    120. for ($i=0;$i <count($arr1);$i++){
    121. echo $arr1[$i],"<br>";
    122. }
    123. $a = array(1,2,3,4,5,8,9,150);
    124. var_dump($a);
    125. echo"<hr>";
    126. foreach($a as $b){
    127. echo$b ,"<br>";
    128. }
    129. echo"<hr>";
    130. $arr =[
    131. 'name' => 'tim',
    132. 'age' => 18,
    133. 'like' => 'geme'
    134. ];
    135. foreach($arr as $caa =>$cod){
    136. echo $caa,'=>',$cod,"<br>";
    137. }
    138. php3
    139. <?php
    140. $b = [
    141. 123 => '十进制',
    142. 0xFF => '十六进制',
    143. 077 => '8进制',
    144. 0b111 => '2进制',
    145. '08' => '字符串',
    146. 3.33 => '浮点数',
    147. '0b111' => '字符串的二进制',
    148. '077' => '字符串的8进制',
    149. //布尔值
    150. true => 'true',
    151. false => 'false',
    152. //null
    153. null => 'null',
    154. ];
    155. echo "<pre>";
    156. var_dump($b);
    157. echo"</pre>";
    158. $arr1 = array(
    159. 10,
    160. 20,
    161. 30,
    162. 40,
    163. 50,
    164. 60,
    165. 70,
    166. 80,
    167. 90,
    168. );
    169. echo"<pre>";
    170. var_dump($arr1);
    171. echo"</pre>";
    172. echo"<hr>";
    173. echo"手动输出:";
    174. echo"<br>";
    175. echo $arr1[0],"<br>";
    176. echo $arr1[1],"<br>";
    177. echo $arr1[2],"<br>";
    178. echo $arr1[3],"<br>";
    179. echo $arr1[4],"<br>";
    180. echo $arr1[5],"<br>";
    181. echo $arr1[6],"<br>";
    182. echo $arr1[7],"<br>";
    183. echo $arr1[8],"<br>";
    184. echo $arr1[9],"<br>";
    185. echo"总长度:",count($arr1);
    186. echo"<hr>";
    187. echo"自动输出:";
    188. echo"<br>";
    189. for ($i=0;$i <count($arr1);$i++){
    190. echo $arr1[$i],"<br>";
    191. }
    192. $a = array(1,2,3,4,5,8,9,150);
    193. var_dump($a);
    194. echo"<hr>";
    195. foreach($a as $b){
    196. echo$b ,"<br>";
    197. }
    198. echo"<hr>";
    199. $arr =[
    200. 'name' => 'tim',
    201. 'age' => 18,
    202. 'like' => 'geme'
    203. ];
    204. foreach($arr as $caa =>$cod){
    205. echo $caa,'=>',$cod,"<br>";
    206. }

    笔记:
    数组下标的强制转换
    下标只出现两种类型: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 可以遍历关联数组

    作业 - 图1