Skip to content

Instantly share code, notes, and snippets.

@HendrikEduard
Last active January 22, 2021 07:17
Show Gist options
  • Save HendrikEduard/46170d7d9c1a4fc7e52ee2f62fc3ffae to your computer and use it in GitHub Desktop.
Save HendrikEduard/46170d7d9c1a4fc7e52ee2f62fc3ffae to your computer and use it in GitHub Desktop.
PHP function that creates a multiplication table / column
<?php
/**
* Creates a multiplication table / column
*
* @param [number] $by - number to multiply by
* @param [number] $begin - number to begin the column
* @param [number] $end - number to end the column
*
* @author Hendrik Eduard Kuiper
* @license The MIT License (MIT)
*/
function multiplication_table($by, $begin, $end) {
for ($i = $begin; $i <= $end; $i++) {
echo $by . ' * '.$i . ' = '. ($by * $i) . '<br />';
}
}
multiplication_table(3, 20, 25);
/* output
3 * 20 = 60
3 * 21 = 63
3 * 22 = 66
3 * 23 = 69
3 * 24 = 72
3 * 25 = 75
The MIT License (MIT)
Copyright (c) 2018, Hendrik Eduard Kuiper
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment