Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Function 1:
- /**
- * Check if A is equal to B.(Just a sample note, not important)
- *
- * @param string A
- * @param string B
- *
- * @return bool
- */
- function checkAandB_1($a, $b){
- if($a === $b)
- return true;
- return false;
- }
- // Function 2:
- /**
- * Check if A is equal to B.(Just a sample note, not important)
- *
- * @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)
- *
- * @return bool
- */
- function checkAandB_2($str){
- if( substr_count($str, ",") === 1 ) {
- $strArr = explode(",",$str);
- if($strArr[0] === $strArr[1])
- return true;
- }
- return false;
- }
- // Function 3: Simulation a overload function
- /**
- * Check if A is equal to B.(Just a sample note, not important)
- *
- * @param string (What's the best annotation to describe this function?)
- *
- * @return bool
- */
- function checkAandB_overload($str, $b = null){
- if(isset($b) && $str === $b){
- return true;
- }elseif( substr_count($str, ",") === 1 ) {
- $strArr = explode(",",$str);
- if($strArr[0] === $strArr[1])
- return true;
- }
- return false;
- }
- var_dump(checkAandB_1("1","2")); // false
- var_dump(checkAandB_1("2","2")); // true
- var_dump(checkAandB_2("1,2")); // false
- var_dump(checkAandB_2("2,2")); // true
- var_dump(checkAandB_overload("1","2")); // false
- var_dump(checkAandB_overload("2","2")); // true
- var_dump(checkAandB_overload("1,2")); // false
- var_dump(checkAandB_overload("2,2")); // true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement