Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. <?php
  2.  
  3. // Function 1:
  4. /**
  5. * Check if A is equal to B.(Just a sample note, not important)
  6. *
  7. * @param string A
  8. * @param string B
  9. *
  10. * @return bool
  11. */
  12. function checkAandB_1($a, $b){
  13. if($a === $b)
  14. return true;
  15. return false;
  16. }
  17.  
  18. // Function 2:
  19. /**
  20. * Check if A is equal to B.(Just a sample note, not important)
  21. *
  22. * @param string Input x,y (<=here, I need to known how to write a right note to describe this function can support input a string combin x and y with a comma in one line)
  23. *
  24. * @return bool
  25. */
  26. function checkAandB_2($str){
  27. if( substr_count($str, ",") === 1 ) {
  28. $strArr = explode(",",$str);
  29. if($strArr[0] === $strArr[1])
  30. return true;
  31. }
  32. return false;
  33. }
  34.  
  35.  
  36. // Function 3: Simulation a overload function
  37. /**
  38. * Check if A is equal to B.(Just a sample note, not important)
  39. *
  40. * @param string (What's the best annotation to describe this function?)
  41. *
  42. * @return bool
  43. */
  44. function checkAandB_overload($str, $b = null){
  45.  
  46. if(isset($b) && $str === $b){
  47. return true;
  48. }elseif( substr_count($str, ",") === 1 ) {
  49. $strArr = explode(",",$str);
  50. if($strArr[0] === $strArr[1])
  51. return true;
  52. }
  53. return false;
  54. }
  55.  
  56.  
  57.  
  58. var_dump(checkAandB_1("1","2")); // false
  59. var_dump(checkAandB_1("2","2")); // true
  60.  
  61. var_dump(checkAandB_2("1,2")); // false
  62. var_dump(checkAandB_2("2,2")); // true
  63.  
  64. var_dump(checkAandB_overload("1","2")); // false
  65. var_dump(checkAandB_overload("2","2")); // true
  66. var_dump(checkAandB_overload("1,2")); // false
  67. var_dump(checkAandB_overload("2,2")); // true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement