-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3e46ee
commit 37c3dd8
Showing
21 changed files
with
610 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Arrays</title> | ||
</head> | ||
<body> | ||
<?php | ||
$brands = array("Toyota","Volkswagen","Subaru","Audi","Range Rover","Lexus","Chevrolet"); | ||
print_r($brands); | ||
|
||
|
||
$brand[0] = "Toyota"; | ||
$brand[1] = "Volkswagen"; | ||
$brand[2] = "Subaru"; | ||
$brand[3] = "Audi"; | ||
$brand[4] = "Range Rover"; | ||
$brand[5] = "Lexus"; | ||
$brand[6] = "Chevrolet"; | ||
|
||
print_r($brand); | ||
|
||
$grades = array("Mike"=>80, "Vincent"=>78, "Victor"=>75); | ||
print_r($grades); | ||
|
||
|
||
$contacts = array( | ||
array("name"=>"Mike Chepkwonyi", | ||
"email"=>"[email protected]"), | ||
array("name"=>"Vincent Sigei", | ||
"email"=>"[email protected]"), | ||
array("name"=>"Victor Sirma", | ||
"email"=>"[email protected]") | ||
); | ||
|
||
echo "Mike Chepkwonyi's Email Id is: ". $contacts[0]["email"]; | ||
?> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Arithmetic</title> | ||
</head> | ||
<body> | ||
<?php | ||
function getSum($num1, $num2){ | ||
$sum = $num1 + $num2; | ||
$subtraction = $num1 - $num2; | ||
$multiplication = $num1 * $num2; | ||
$division = $num1 / $num2; | ||
echo "The sum of $num1 and $num2 is: $sum <br>"; | ||
echo "The subtraction of $num1 and $num2 is: $subtraction <br>"; | ||
echo "The multiplication of $num1 and $num2 is: $multiplication <br>"; | ||
echo "The division of $num1 and $num2 is: $division <br>"; | ||
} | ||
|
||
getSum(20, 30); | ||
?> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>PHP Function returning values</title> | ||
</head> | ||
<body> | ||
<?php | ||
//Defining a function | ||
|
||
function getSum($num1, $num2){ | ||
$total = $num1 + $num2; | ||
return $total; | ||
} | ||
|
||
//printing returned value | ||
echo getSum(50, 100); | ||
?> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
function amortiazationTable($pNum, $periodicPayment, $balance, $monthlyInterest){ | ||
// Calculate payment interest | ||
$paymentInterest = round($balance * $monthlyInterest, 2); | ||
|
||
//Calculate payment principal | ||
$paymentPrincipal = round($periodicPayment - $paymentInterest, 2); | ||
|
||
//Deduct principal from the remaining balance | ||
$newBalance = round($balance - $paymentPrincipal, 2); | ||
|
||
//If new balance < Monthly payment, set to zero | ||
if($newBalance < $paymentPrincipal){ | ||
$newBalance = 0; | ||
} | ||
|
||
printf("<tr><td>%s</td>", $pNum); | ||
printf("<tr><td>%s</td>", number_format($newBalance, 2)); | ||
printf("<tr><td>%s</td>", number_format($periodicPayment, 2)); | ||
printf("<tr><td>%s</td>", number_format($paymentPrincipal, 2)); | ||
printf("<tr><td>%s</td>", number_format($paymentInterest, 2)); | ||
|
||
#if balance not yet zero, recursively call amortizationTable() | ||
if($newBalance > 0){ | ||
$pNum++; | ||
amortiazationTable($pNum, $periodicPayment, $newBalance, $monthlyInterest); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
//Loan balance | ||
$balance = 6000000.00; | ||
//Loan interest rate | ||
$interestRate = 0.0575; | ||
//Monthly interest rate | ||
$monthlyInterest = $interestRate/12; | ||
//Term length of the loan, in Years | ||
$termLength = 5; | ||
//Number of payments per year | ||
$paymentsPerYear = 12; | ||
//Payments iteration | ||
$paymentNumber = 1; | ||
//Determine total number payments | ||
$totalPayments = $termLength * $paymentsPerYear; | ||
//Determine interst component of periodic payments | ||
$intCalc = 1+$interestRate/$paymentsPerYear; | ||
//Determine periodic payment | ||
$periodicPayment = $balance * pow($intCalc, $totalPayments)*($intCalc-1)/(pow($intCalc,$totalPayments)-1); | ||
//Round periodic payments to two decimal places | ||
$periodicPayment = round($periodicPayment, 2); | ||
|
||
//Create table | ||
echo "<table width='50%' align='center' border='1'>"; | ||
echo "<tr> | ||
<th>Payment Number</th><th>Balance</th> | ||
<th>Payment</th><th>Principal</th><th>Interest</th> | ||
</tr>"; | ||
|
||
//call recursive function | ||
amortiazationTable($paymentNumber, $periodicPayment, $balance, $monthlyInterest); | ||
//close table | ||
echo '</table>'; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>PHP Returning Array with Functions</title> | ||
</head> | ||
<body> | ||
<?php | ||
function divideNumbers($dividend, $divisor){ | ||
$quotient = $dividend/$divisor; | ||
$array = array($dividend, $divisor, $quotient); | ||
return $array; | ||
} | ||
|
||
//assign Variables as if they were an array | ||
|
||
list($dividend, $divisor, $quotient) = divideNumbers(10, 2); | ||
echo $dividend."<br>"; | ||
echo $divisor."<br>"; | ||
echo $quotient."<br>"; | ||
?> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>PHP Functions</title> | ||
</head> | ||
<body> | ||
<?php | ||
//Defining a function | ||
function leo(){ | ||
echo "Today is" .date('l', mktime()); | ||
} | ||
//calling of a function | ||
leo(); | ||
?> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
echo PHP_PEAR_SYSCONF_DIR; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>use of echo statement</title> | ||
</head> | ||
<body> | ||
<h1> | ||
<?php echo "world safari rally championship was hold in naivasha kenya"; ?> | ||
</h1> | ||
<h2> | ||
<?php echo "world safari rally championship was hold in naivasha kenya"; ?> | ||
</h2> | ||
<h3> | ||
<?php echo "world safari rally championship was hold in naivasha kenya"; ?> | ||
</h3> | ||
<h4> | ||
<?php echo "world safari rally championship was hold in naivasha kenya"; ?> | ||
</h4> | ||
<h5> | ||
<?php echo "world safari rally championship was hold in naivasha kenya"; ?> | ||
</h5> | ||
<h6> | ||
<?php echo "world safari rally championship was hold in naivasha kenya"; ?> | ||
</h6> | ||
/* this is a comment */ | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Example of PHP GET method</title> | ||
</head> | ||
<body> | ||
<?php | ||
if (isset($_GET['name'])){ | ||
echo "<p>Hi, ".$_GET['name']."</p>"; | ||
echo "<p>Your username is , ".$_GET['username']."</p>"; | ||
echo "<p>Your Email is, ".$_GET['email']."</p>"; | ||
echo "<p>You are , ".$_GET['age']." years old.</p>"; | ||
} | ||
|
||
?> | ||
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="get"> | ||
<label for="inputName">Name:</label> | ||
<input type="text" name="name" id="inputName"> | ||
<br><br> | ||
<!-- username, email and age --> | ||
<label for="inputUsername">Username:</label> | ||
<input type="text" name="username" id="inputUsername"> | ||
<br><br> | ||
<label for="inputEmail">Email:</label> | ||
<input type="email" name="email" id="inputEmail"> | ||
<br><br> | ||
<label for="inputAge">Age:</label> | ||
<input type="text" name="age" id="inputAge"> | ||
<br><br> | ||
<input type="submit" Value="Submit"> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Strings</title> | ||
</head> | ||
<body> | ||
<?php | ||
$t = date("H"); | ||
if($t>"20"){ | ||
echo "Have a good day"; | ||
} else { | ||
echo "Have a good night"; | ||
} | ||
|
||
$d = date("M"); | ||
if($d == "Mon"){ | ||
echo "Time and Day to got to work"; | ||
} else if($d == "SAT") { | ||
echo "Enjoy your Weekend"; | ||
} else { | ||
echo "Have a nice day"; | ||
} | ||
?> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
function amortizationTable($pNum, $periodicPayment, $balance, $monthlyInterest) | ||
{ | ||
// Calculate payment interest | ||
$paymentInterest = round($balance * $monthlyInterest, 2); | ||
// Calculate payment principal | ||
$paymentPrincipal = round($periodicPayment - $paymentInterest, 2); | ||
// Deduct principal from remaining balance | ||
$newBalance = round($balance - $paymentPrincipal, 2); | ||
// If new balance < monthly payment, set to zero | ||
if ($newBalance < $paymentPrincipal) { | ||
$newBalance = 0; | ||
} | ||
printf("<tr><td>%d</td>", $pNum); | ||
printf("<td>$%s</td>", number_format($newBalance, 2)); | ||
printf("<td>$%s</td>", number_format($periodicPayment, 2)); | ||
printf("<td>$%s</td>", number_format($paymentPrincipal, 2)); | ||
printf("<td>$%s</td></tr>", number_format($paymentInterest, 2)); | ||
# If balance not yet zero, recursively call amortizationTable() | ||
if ($newBalance > 0) { | ||
$pNum++; | ||
amortizationTable($pNum, $periodicPayment, | ||
$newBalance, $monthlyInterest); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
// Loan balance | ||
$balance = 6000000.00; | ||
// Loan interest rate | ||
$interestRate = .0575; | ||
// Monthly interest rate | ||
$monthlyInterest = $interestRate / 12; | ||
// Term length of the loan, in years. | ||
$termLength = 5; | ||
// Number of payments per year. | ||
$paymentsPerYear = 12; | ||
// Payment iteration | ||
$paymentNumber = 1; | ||
// Determine total number payments | ||
$totalPayments = $termLength * $paymentsPerYear; | ||
// Determine interest component of periodic payment | ||
$intCalc = 1 + $interestRate / $paymentsPerYear; | ||
// Determine periodic payment | ||
$periodicPayment = $balance * pow($intCalc,$totalPayments) * ($intCalc - 1) / | ||
(pow($intCalc,$totalPayments) - 1); | ||
// Round periodic payment to two decimals | ||
$periodicPayment = round($periodicPayment,2); | ||
// Create table | ||
echo "<table width='50%' align='center' border='1'>"; | ||
echo "<tr> | ||
<th>Payment Number</th><th>Balance</th> | ||
<th>Payment</th><th>Principal</th><th>Interest</th> | ||
</tr>"; | ||
// Call recursive function | ||
amortizationTable($paymentNumber, $periodicPayment, $balance, | ||
$monthlyInterest); | ||
// Close table | ||
echo "</table>"; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Loops</title> | ||
</head> | ||
<body> | ||
<?php | ||
|
||
$i = 30; | ||
while($i <= 34){ | ||
$i++; | ||
echo "The Age-group for the persons are ".$i."<br>"; | ||
} | ||
|
||
|
||
|
||
$i = 30; | ||
do{ | ||
$i++; | ||
echo "The Age-group is $i"."<br>"; | ||
} while ($i <= 34); | ||
|
||
|
||
|
||
for($i = 30; $i<=34; $i++){ | ||
echo "The Age-group is $i"."<br>"; | ||
} | ||
|
||
|
||
$brands = array("Toyota","Volkswagen","Subaru","Audi","Range Rover","Lexus","Chevrolet"); | ||
foreach($brands as $value){ | ||
echo "$value <br>"; | ||
} | ||
?> | ||
</body> | ||
</html> |
Binary file not shown.
Oops, something went wrong.