Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
edabit php very easy
<?php
function addition($number1, $number2) {
return $number1 + $number2;
}
echo addition(3, 2) . "<br />";
echo addition(-3, -6) . "<br />";
echo addition(7, 3) . "<br />";
#####################################################################
function addition($number) {
return $number++;
}
echo addition(0) . "<br />";
echo addition(9) . "<br />";
echo addition(-3) . "<br />";
#####################################################################
function convert($minutes) {
return $minutes * 60;
}
echo "5 Minutes = " . convert(5) . "<br />";
echo "3 Minutes = " . convert(3) . "<br />";
echo "2 Minutes = " . convert(2) . "<br />";
#####################################################################
function giveMeSomething($string) {
return "something " . $string;
}
echo giveMeSomething("is better than nothing") . "<br />";
echo giveMeSomething("Bob Jane") . "<br />";
echo giveMeSomething("something") . "<br />";
#####################################################################
function triArea($base, $height) {
return ($base * $height ) / 2;
}
echo "triArea(3, 2) : " . triArea(3, 2) . "<br />";
echo "triArea(7, 4) : " . triArea(7, 4) . "<br />";
echo "triArea(10, 10) : " . triArea(10, 10) . "<br />";
#####################################################################
function nextEdge($side1, $side2) {
return ($side1 + $side2) - 1;
}
echo "nextEdge(8, 10) : " . nextEdge(8, 10) . "<br />";
echo "nextEdge(5, 7) : " . nextEdge(5, 7) . "<br />";
echo "nextEdge(9, 2) : " . nextEdge(9, 2) . "<br />";
#####################################################################
function calcAge($age) {
return $age * 365;
}
echo "calcAge(65) : " . calcAge(65) . "<br />";
echo "calcAge(0) : " . calcAge(0) . "<br />";
echo "calcAge(20) : " . calcAge(20) . "<br />";
#####################################################################
function howManySeconds($hours) {
#return $hours * 60 * 60;
return $hours * 3600;
}
echo "howManySeconds(2) : " . howManySeconds(2). "<br />";
echo "howManySeconds(10) : " . howManySeconds(10). "<br />";
echo "howManySeconds(24) : " . howManySeconds(24). "<br />";
#####################################################################
function lessThanOrEqualToZero($number) {
if($number < 1)
return "true";
else
return "false";
}
echo "lessThanOrEqualToZero(5) : " . lessThanOrEqualToZero(5). "<br />";
echo "lessThanOrEqualToZero(0) : " . lessThanOrEqualToZero(0). "<br />";
echo "lessThanOrEqualToZero(-2) : " . lessThanOrEqualToZero(-2). "<br />";
#####################################################################
function getFirstValue($numbers) {
return $numbers[0];
}
echo "getFirstValue([1, 2, 3]) : " . getFirstValue([1, 2, 3]). "<br />";
echo "getFirstValue([80, 5, 100]) : " . getFirstValue([80, 5, 100]). "<br />";
echo "getFirstValue([-500, 0, 50]) : " . getFirstValue([-500, 0, 50]). "<br />";
#####################################################################
function animals($chickens, $cows, $pigs) {
$chickensLegs = 2;
$cowsLegs = 4;
$pigsLegs = 4;
return ($chickens * $chickensLegs) + ($cows * $cowsLegs) + ($pigs * $pigsLegs);
#return $chickens * 2 + $cows * 4 + $pigs * 4;
}
echo "animals(2, 3, 5) : " . animals(2, 3, 5). "<br />";
echo "animals(1, 2, 3) : " . animals(1, 2, 3). "<br />";
echo "animals(5, 2, 8) : " . animals(5, 2, 8). "<br />";
#####################################################################
/*
And :
true && true = true
false && true = false
true && fasle= false
false && false= false
*/
function andCompare($op1, $op2) {
# op => operator
if($op1 && $op2)
return "true";
else
return "false";
}
echo "andCompare(true, false) : " . andCompare(true, false). "<br />";
echo "andCompare(true, true) : " . andCompare(true, true). "<br />";
echo "andCompare(false, true) : " . andCompare(false, true). "<br />";
echo "andCompare(false, false) : " . andCompare(false, false). "<br />";
#####################################################################
function findPerimeter($width, $height) {
return ($width + $height) * 2;
}
echo "findPerimeter(6, 7) : " . findPerimeter(6, 7). "<br />";
echo "findPerimeter(20, 10) : " . findPerimeter(20, 10). "<br />";
echo "findPerimeter(2, 9) : " . findPerimeter(2, 9). "<br />";
#####################################################################
function is_same_num($number1, $number2) {
if($number1 === $number2)
return "true";
else
return "false";
}
echo "is_same_num(4, 8) : " . is_same_num(4, 8). "<br />";
echo "is_same_num(2, 2) : " . is_same_num(2, 2). "<br />";
echo "is_same_num(2, '2') : " . is_same_num(2, "2"). "<br />";
#####################################################################
function isEmpty($string) {
if(empty($string))
return "true";
else
return "false";
}
echo 'isEmpty("") : ' . isEmpty("") . "<br />";
echo 'isEmpty(" ") : ' . isEmpty(" ") . "<br />";
echo 'isEmpty("a") : ' . isEmpty("a") . "<br />";
#####################################################################
function squared($number) {
return $number * $number;
}
echo "squared(5) : " . squared(5) . "<br />";
echo "squared(9) : " . squared(9) . "<br />";
echo "squared(100) : " . squared(100) . "<br />";
#####################################################################
function convert($hours, $minutes) {
return ($hours * 60 * 60) + ($minutes * 60);
}
echo "convert(1, 3) = " . convert(1, 3) . "<br />";
echo "convert(2, 0) = " . convert(2, 0) . "<br />";
echo "convert(0, 0) = " . convert(0, 0) . "<br />";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment