Instantly share code, notes, and snippets.
Richard Perez richardpq
- Canada
| Verifying that +richardpq is my blockchain ID. https://onename.com/richardpq |
richardpq
/ validate.php
Created
Usually when you want to validate if the parameters you are receiving from a client has valid keys, you use a foreach to compare each parameter key with an array of valid keys, but this way is shorter and faster.
| <?php |
| $invalidParameters = ['Key_1' => 1, 'Key_2' => 2, 'No_valid' => 3]; |
| $validParameters = ['Key_1' => 1, 'Key_2' => 2]; |
| function validParameters($parameters) { |
| $validKeys = ['Key_1', 'Key_2', 'Key_3', 'Key_4']; |
| $keys = array_keys($parameters); |
| return array_diff($keys, $validKeys) ? false : true; |
| <?php |
| public function factorial($number) |
| { |
| if ($number == 1) { |
| return 1; |
| } |
| $total = $number * $this->factorial($number - 1); |
| return $total; |
richardpq
/ magicTrick.php
Last active
This is a very basic algorithm for a "magic trick" where you choose the same letter 3 times (in your mind) from a set of different letters distributed in 3 columns and the system will guess which one you choose.
| <?php |
| $letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U']; |
| shuffle($letters); |
| $count = 1; |
| $message = ""; |
| do { |
richardpq
/ SplClassLoader.php
Last active
โ forked from jwage/SplClassLoader.php
| <?php |
| /* |
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
