Blogger Information
Blog 28
fans 0
comment 0
visits 15753
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0810 作业 数组的键值操作
︷肉園耔︷
Original
566 people have browsed it
  1. <?php
  2. //后端程序员自定义 salt
  3. $salt='tanacity.1';
  4. //后端接收用户数据
  5. $pwd=$_GET['password'];
  6. //给用户的密码加盐
  7. echo sha1('phpcn'.$salt).'<br>';
  8. //登录
  9. $pwd_real= 'wwwphpxn';
  10. echo sha1($pwd_real.$salt);
  11. ob_clean();
  12. //密码散列处理 创建密码的散列(hash)
  13. $hash= password_hash('wwwphpcn',PASSWORD_BCRYPT);
  14. //密码验证 password_verify() 是否和散列值匹配
  15. /*$res=password_verify('wwwphpca',$hash);
  16. var_dump($res);*/
  17. if(!password_verify('wwwphpcn',$hash))
  18. echo '输入的密码不正确';
  19. $url="http://localhost/demo8/1.php?name=admin&gender=1";
  20. echo '<pre>';
  21. print_r($_GET);
  22. echo '<br>';
  23. print_r($_SERVER);
  24. echo $_SERVER['QUERY_STRING'];
  25. $res=parse_url($url);
  26. print_r($res);
  27. //解析URL 返回他的组成部分;
  28. parse_str($_SERVER['QUERY_STRING'],$result);
  29. print_r($result);
  30. //http_build_query() api接口安全 生成url_encode 之后的请求字符串,数组 转换成 字符串
  31. $params =['name'=>'admin','gender'=>1];
  32. $res=http_build_query($params);
  33. print_r($res);
  34. <?php
  35. /*
  36. * 数组:是一组有序成员(键值对)的集合
  37. * 1.索引数组 键是从0开始的整数
  38. * 2.关联数组 键是语义话的字符串
  39. *
  40. * */
  41. //多维数组
  42. $arr =range(1,100,1);
  43. print_r($arr);
  44. ob_clean();
  45. //添加数组成员
  46. //array_unshift()从头部添加
  47. $arr=['uniapp'];
  48. array_unshift($arr,'css3');
  49. array_unshift($arr,'composer');
  50. print_r($arr);
  51. //array_push()从尾部添加数组成员
  52. array_push($arr,'vue-webpack');
  53. array_push($arr,'vue-cli');
  54. print_r($arr);
  55. ob_clean();
  56. //删除数组
  57. //1 array_shift()返回删除的数组元素
  58. $num = range(1,39,4);
  59. print_r($num);
  60. var_dump(array_shift($num));
  61. var_dump(array_shift($num));
  62. print_r($num);
  63. ob_clean();
  64. $letter =range('a','z',3);
  65. print_r($letter);
  66. // 从尾部删除
  67. echo array_pop($letter);
  68. echo array_pop($letter);
  69. echo array_pop($letter);
  70. echo array_pop($letter);
  71. print_r($letter);
  72. ob_clean();
  73. //array_splice() 任意位置删除数组元素
  74. $arr =range(1,36,4);
  75. var_dump($arr);
  76. $res=array_splice($arr,2,3);
  77. var_dump($res);
  78. <?php
  79. /*
  80. * 键值操作函数
  81. * array_keys() 获取数组的键组成新的数组
  82. * */
  83. $stuInfo =['name'=>'何四','stdNum'=>23123123,'tel'=>156134691021,'bouns'=>8000];
  84. var_dump(array_keys($stuInfo));
  85. //判断某个键是否存在
  86. $flag=false;
  87. foreach($stuInfo as $k=>$v){
  88. if($k === 'bouns') $flag=true;
  89. }
  90. echo $flag ? '存在' : '不存在';
  91. ob_clean();
  92. $stuInfo =['name'=>'何四','stdNum'=>23123123,'tel'=>156134691021,'bouns'=>8000];
  93. //array_key_exists() 判断数组是否存在指定的键名(索引)
  94. var_dump( array_key_exists('bouns',$stuInfo));
  95. ob_clean();
  96. //in_array()判断数组中是否存在某个值 存在的值返回 ture ,不存在的值返回false
  97. var_dump(in_array(8002,$stuInfo));
  98. ob_clean();
  99. //作业返回数组所有值建立数字索引
  100. //$arr =[4=>10,1=>22,9=>55,0=>255];
  101. $a=array("Name"=>"Bill","Age"=>"60","Country"=>"USA");
  102. var_dump($arr1=array_values($a));
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post