diff --git a/arrays.php b/arrays.php new file mode 100644 index 0000000..94b528a --- /dev/null +++ b/arrays.php @@ -0,0 +1,38 @@ + + + +Arrays + + + 80, "Vincent"=>78, "Victor"=>75); + print_r($grades); + + + $contacts = array( + array("name"=>"Mike Chepkwonyi", + "email"=>"chepkwonyimike@gmail.com"), + array("name"=>"Vincent Sigei", + "email"=>"sigeivincent@hotmail.com"), + array("name"=>"Victor Sirma", + "email"=>"sirma2021@gmail.com") + ); + + echo "Mike Chepkwonyi's Email Id is: ". $contacts[0]["email"]; + ?> + + \ No newline at end of file diff --git a/den_functions/arithmetic.php b/den_functions/arithmetic.php new file mode 100644 index 0000000..bc258d2 --- /dev/null +++ b/den_functions/arithmetic.php @@ -0,0 +1,23 @@ + + + + + Arithmetic + + + "; + echo "The subtraction of $num1 and $num2 is: $subtraction
"; + echo "The multiplication of $num1 and $num2 is: $multiplication
"; + echo "The division of $num1 and $num2 is: $division
"; + } + + getSum(20, 30); + ?> + + \ No newline at end of file diff --git a/den_functions/functionreturning.php b/den_functions/functionreturning.php new file mode 100644 index 0000000..4a0cf1b --- /dev/null +++ b/den_functions/functionreturning.php @@ -0,0 +1,20 @@ + + + + + PHP Function returning values + + + + + \ No newline at end of file diff --git a/den_functions/payment.php b/den_functions/payment.php new file mode 100644 index 0000000..7053099 --- /dev/null +++ b/den_functions/payment.php @@ -0,0 +1,64 @@ +%s", $pNum); + printf("%s", number_format($newBalance, 2)); + printf("%s", number_format($periodicPayment, 2)); + printf("%s", number_format($paymentPrincipal, 2)); + printf("%s", 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 ""; +echo " + + +"; + +//call recursive function +amortiazationTable($paymentNumber, $periodicPayment, $balance, $monthlyInterest); +//close table +echo '
Payment NumberBalancePaymentPrincipalInterest
'; +?> \ No newline at end of file diff --git a/den_functions/reuturningArrayofFunctions.php b/den_functions/reuturningArrayofFunctions.php new file mode 100644 index 0000000..6190040 --- /dev/null +++ b/den_functions/reuturningArrayofFunctions.php @@ -0,0 +1,23 @@ + + + + + PHP Returning Array with Functions + + +"; + echo $divisor."
"; + echo $quotient."
"; +?> + + \ No newline at end of file diff --git a/den_functions/t.php b/den_functions/t.php new file mode 100644 index 0000000..ac1ff60 --- /dev/null +++ b/den_functions/t.php @@ -0,0 +1,17 @@ + + + + + PHP Functions + + + + + \ No newline at end of file diff --git a/derekbanas.php b/derekbanas.php new file mode 100644 index 0000000..5464ee9 --- /dev/null +++ b/derekbanas.php @@ -0,0 +1,2 @@ + + + +use of echo statement + + +

+ +

+

+ +

+

+ +

+

+ +

+
+ +
+
+ +
+/* this is a comment */ + + \ No newline at end of file diff --git a/get.php b/get.php new file mode 100644 index 0000000..40f3acf --- /dev/null +++ b/get.php @@ -0,0 +1,36 @@ + + + + + + + Example of PHP GET method + + + Hi, ".$_GET['name']."

"; + echo "

Your username is , ".$_GET['username']."

"; + echo "

Your Email is, ".$_GET['email']."

"; + echo "

You are , ".$_GET['age']." years old.

"; + } + + ?> +
" method="get"> + + +

+ + + +

+ + +

+ + +

+ +
+ + \ No newline at end of file diff --git a/ifstatement.php b/ifstatement.php new file mode 100644 index 0000000..3bed094 --- /dev/null +++ b/ifstatement.php @@ -0,0 +1,25 @@ + + + +Strings + + + "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"; + } + ?> + + \ No newline at end of file diff --git a/loan1.php b/loan1.php new file mode 100644 index 0000000..a961d9d --- /dev/null +++ b/loan1.php @@ -0,0 +1,60 @@ +%d", $pNum); +printf("$%s", number_format($newBalance, 2)); +printf("$%s", number_format($periodicPayment, 2)); +printf("$%s", number_format($paymentPrincipal, 2)); +printf("$%s", 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 ""; +echo " + + +"; +// Call recursive function +amortizationTable($paymentNumber, $periodicPayment, $balance, +$monthlyInterest); +// Close table +echo "
Payment NumberBalancePaymentPrincipalInterest
"; +?> \ No newline at end of file diff --git a/loops.php b/loops.php new file mode 100644 index 0000000..11c32c3 --- /dev/null +++ b/loops.php @@ -0,0 +1,36 @@ + + + +Loops + + + "; + } + + + + $i = 30; + do{ + $i++; + echo "The Age-group is $i"."
"; + } while ($i <= 34); + + + + for($i = 30; $i<=34; $i++){ + echo "The Age-group is $i"."
"; + } + + + $brands = array("Toyota","Volkswagen","Subaru","Audi","Range Rover","Lexus","Chevrolet"); + foreach($brands as $value){ + echo "$value
"; + } + ?> + + \ No newline at end of file diff --git a/notes.docx b/notes.docx new file mode 100644 index 0000000..9cf3745 Binary files /dev/null and b/notes.docx differ diff --git a/phpobjects.php b/phpobjects.php new file mode 100644 index 0000000..742c797 --- /dev/null +++ b/phpobjects.php @@ -0,0 +1,19 @@ + + + + + + + str; + } + } + $town = new county; + var_dump($town); + ?> + + + diff --git a/post.php b/post.php new file mode 100644 index 0000000..f691f94 --- /dev/null +++ b/post.php @@ -0,0 +1,35 @@ + + + + + + + Example of PHP POST method + + + Hi, ".$_POST['name']."

"; + echo "

Your username is, ".$_POST['username']."

"; + echo "

Your email is, ".$_POST['email']."

"; + echo "

You are, ".$_POST['age']." years old

"; + } + ?> +
" method="post"> + + +

+ + + +

+ + +

+ + +

+ +
+ + \ No newline at end of file diff --git a/request.php b/request.php new file mode 100644 index 0000000..f6691a8 --- /dev/null +++ b/request.php @@ -0,0 +1,35 @@ + + + + + + + Example of PHP $_REQUEST variable + + + Hi, ".$_REQUEST['name']."

"; + echo "

Your username is, ".$_REQUEST['username']."

"; + echo "

Your email is, ".$_REQUEST['email']."

"; + echo "

You are, ".$_REQUEST['age']." years old

"; + } + ?> +
" method="post"> + + +

+ + + +

+ + +

+ + +

+ +
+ + \ No newline at end of file diff --git a/sandbox.php b/sandbox.php new file mode 100644 index 0000000..a408671 --- /dev/null +++ b/sandbox.php @@ -0,0 +1,10 @@ + + + +Strings + + + "; + echo 'Hujambo my-religion is, $my_religion
'; + + + // *Strings enclosed in single quotes are treated literally + // *while those delimited by double quotes are replaces variables with string respresentations of their values + + echo 'I\'ll be right back'; + $karibu = 'Welcome to Noreb Region'; + echo strlen($karibu); + ?> + + \ No newline at end of file diff --git a/switch.php b/switch.php new file mode 100644 index 0000000..943a453 --- /dev/null +++ b/switch.php @@ -0,0 +1,31 @@ + + + +Switch + + + + + \ No newline at end of file diff --git a/uasort.php b/uasort.php new file mode 100644 index 0000000..c1e40a5 --- /dev/null +++ b/uasort.php @@ -0,0 +1,43 @@ + + + + + + + Sorting multidimensional arrays + + + + array('name'=>'Name','grade'=>XX.X) + $students = array( + 001 => array('name' => 'Nafula','grade' => 98.5), + 002 => array('name' => 'Wanjiku','grade' => 81.5), + 003 => array('name' => 'Adeku','grade' => 94.0), + 004 => array('name' => 'Olama','grade' => 85.1), + 005 => array('name' => 'Wangoi','grade' => 74.6) + ); + + //Name sorting function + function name_sort($x, $y){ + return strcasecmp($x['name'], $y['name']); + } + //Sort the grade function in descending order + function grade_sort($x, $y){ + return ($x['grade']<$y['grade']); + } + //Print the array as it is: + echo '

The Array in its Original structure:

'.print_r($students, 1). '
'; + //sort by name: + ?> + + \ No newline at end of file diff --git a/variables.php b/variables.php new file mode 100644 index 0000000..0344465 --- /dev/null +++ b/variables.php @@ -0,0 +1,44 @@ + + + +Print statement illustation + + +"; + print $num; + print "
"; + print $phones[0]; + + $color1 = "Red"; + $color2 = "Green"; + $color3 = "Blue"; + echo $color1; + echo "
"; + echo $color2; + echo "
"; + echo $color3; + +?> +

Common Vehicles brands in kenyan roads

+ ".$toyota."
".$lexus."
".$subaru."
".$audi; + + ?> +

PHP Constants

+ + + + \ No newline at end of file