Skip to content

Instantly share code, notes, and snippets.

@VaguelyOnline
Created March 14, 2022 12:51
Show Gist options
  • Save VaguelyOnline/07071de1f6a7bc0d48ada6aa1c83537d to your computer and use it in GitHub Desktop.
Save VaguelyOnline/07071de1f6a7bc0d48ada6aa1c83537d to your computer and use it in GitHub Desktop.
<?php
function calculateSum(int $min, int $max) {
$tally = 0;
for ($i = $min; $i < $max; $i++) {
$tally += $i;
}
return $tally;
}
// Problem 1:
function getSumsFor(array $upTos) {
// for loop? How many items are in the array?
// foreach?
// Handle as a queue
// Pop the item off the end - and handle it
// stop when the queue is empty
}
// Assume range is 0, up to the value
$upTos1 = [2, 10, 20];
$results = getSumsFor($upTos1);
// Extension - allow the variable to specify a min and a max for each (rather than assume 0 up to ...)
$upTos2 = [
// ??
];
print_r($results);
// Problem 2:
// Represent the new cohort as an array of objects - see: https://www.php.net/manual/en/language.oop5.basic.php
$cohort = [
$person1, // instance of a 'User' class that holds the data for a single user
$person2,
...
];
// All done? Continue to work through the Web Essentials online material
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment