Skip to content

Instantly share code, notes, and snippets.

View Mwamitovi's full-sized avatar
🇺🇬
For Greater Horizons

Matovu Mwamitovi

🇺🇬
For Greater Horizons
  • https://kanzucode.com
  • Kampala, Uganda, East-Africa
View GitHub Profile
<?php
// Chapter-12: Exercises
// Question-1
// 1. This program has a syntax error in it:
$name = 'Umberto';
function say_hello() {
print 'Hello, ';
<?php
// Chapter-10: Exercises
// Question-1
// 1. Make a web page that uses a cookie to keep track of how many times a user has viewed the page.
// The first time a particular user looks at the page, it should print something like “Number of views: 1.”
// The second time the user looks at the page, it should print “Number of views: 2,” and so on.
// Answer-1
<?php
// Chapter-8: Exercises
// The following exercises use a database table called dishes with the following structure:
// -- CREATE TABLE dishes (
// -- dish_id INT,
// -- dish_name VARCHAR(255),
// -- price DECIMAL(4,2),
// -- is_spicy INT
// -- )
<?php
// Chapter-7: Exercises
// Question-1
// 1. What does $_POST look like when the following form is submitted with the third option in the Braised Noodles menu selected,
// the first and last options in the Sweet menu selected, and 4 entered into the text box? ?>
<form method="POST" action="order.php">
Braised Noodles with: <select name="noodle">
<option>crab meat</option>
// The PricedEntree class referencing that namespace:
class PricedEntree extends Entree {
public function __construct($name, $ingredients) {
parent::__construct($name, $ingredients);
foreach ($this->ingredients as $ingredient) {
if (! $ingredient instanceof \Meals\Ingredient) {
throw new Exception('Elements of $ingredients must be Ingredient objects');
}
}
<?php
// Chapter-5
// Question-1
// 1. Write a function to return an HTML <img /> tag.
// The function should accept a mandatory argument of the image URL and optional arguments for alt text, height, and width.
// Answer-1
@Mwamitovi
Mwamitovi / 4_data-groups.php
Created January 29, 2025 02:48
learningPHP: Chapter-4
<?php
// Chapter-4: Exercises
// Question-1
// 1. According to the US Census Bureau, the 10 largest American cities (by population) in 2010 were as follows:
// • New York, NY (8,175,133 people)
// • Los Angeles, CA (3,792,621)
// • Chicago, IL (2,695,598)
// • Houston, TX (2,100,263)
@Mwamitovi
Mwamitovi / 2_data.php
Last active January 29, 2025 06:44
learningPHP: Chapters
<?php
// Chapter - 2: Exercises
// Question-1
// 1. Find the errors in this PHP program:
// 1. The opening PHP tag should be just <?php with no space between the <? and php.
// 2. Because the string I'm fine contains a ',
// it should be surrounded by double quotes ("I'm fine") or the ' should be escaped ('I\'m fine').
@Mwamitovi
Mwamitovi / 3_logic.php
Last active January 29, 2025 02:08
learningPHP: Chapter-3
<?php
// Chapter - 3: Exercises
// Question-1
// 1. Without using a PHP program to evaluate them, determine whether each of
// these expressions is true or false:
// a. 100.00 - 100
// b. "zero"
// c. "false"
@Mwamitovi
Mwamitovi / config.js
Created August 6, 2020 14:25
Serve a react project on Heroku
// Step-1:
// create a script server file at the project root e.g. server.js
const path = require('path');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const publicPath = path.join(__dirname, 'build');
// serve the build folder