Blogger Information
Blog 20
fans 0
comment 1
visits 13144
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php 常用函数练习和分支判断语句
zg的php学习
Original
591 people have browsed it

php 常用函数练习和分支判断语句

常用函数

  1. //加密
  2. echo md5('abcde');//ab56b4d92b40713acc5af89985d4b786
  3. echo '<hr/>';
  4. echo sha1('abcde');//03de6c570bfe24bfc328ccd7ca46b76eadaf4334
  5. echo '<hr/>';
  6. //...归并参数
  7. function sum(...$args){
  8. $sum=0;
  9. foreach($args as $key=>$value){
  10. $sum += $value;
  11. };
  12. return $sum;
  13. }
  14. echo sum(1,2,3,4,5,6,7,8,9,10);
  15. //数组函数
  16. //count() 统计数组元素属性的个数
  17. $arr=[
  18. 'name'=>'zhang',
  19. 'sex'=>'male',
  20. 'age'=>18,
  21. 'name1'=>'zhang',
  22. 'sex1'=>'male',
  23. 'age1'=>32
  24. ];
  25. echo count($arr);
  26. echo '<hr/>';
  27. //删除数组元素
  28. unset($arr['sex']);
  29. print_r($arr);
  30. //删除数组中重复的元素(值重复)
  31. print_r(array_unique($arr));
  32. //合并两个数组
  33. $arr1 = [
  34. 'join',
  35. 'shu'
  36. ];
  37. print_r(array_merge($arr,$arr1));
  38. //将数组的元素值转成按指定的分隔符分割的字符串
  39. $arrStr = implode(',',$arr);
  40. echo $arrStr;
  41. echo '<hr/>';
  42. //将指定分隔符分割的字符串转为数组(索引数组)
  43. $arrResult = explode(',',$arrStr);
  44. print_r($arrResult);

条件分支语句

  1. //三元运算符 表达式?语句块1:语句块2;
  2. $rq = '二';
  3. $w = ($rq == '六' or $rq == '日') ? '休息' : '上课' ;
  4. echo $w;
  5. echo '<hr/>';
  6. //if语句
  7. $total = '85';
  8. if($total >= 90){
  9. echo '优秀';
  10. }else if($total >= 80){
  11. echo '良好';
  12. }else if($total >= 60){
  13. echo '及格';
  14. }else{
  15. echo '不及格';
  16. }
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