This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace CodeBundle\Functions; | |
/** | |
* Class MaxiLenDiff | |
* @package CodeBundle\Functions | |
* @see https://www.codewars.com/kata/maximum-length-difference/train/php | |
*/ | |
class MaxiLenDiff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('DB_USERNAME', 'root'); | |
define('DB_PASSWORD', 'Hoang123'); | |
define('DB_NAME', 'session_example'); | |
define('DB_SERVER', 'localhost'); | |
/* Attempt to connect to MySQL database */ | |
/** @var mysqli $mysqli */ | |
$mysqli = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Example of password hashing and verification with password_hash and | |
* password_verify | |
* | |
* This script is intended to be run from the command line | |
* like so: 'php -f password_hash_example.php' | |
* | |
* @see http://stackoverflow.com/a/20809916/1134565 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr = array( | |
array( 1, 0, 0 ), | |
array( 2, 0, 0 ), | |
array( 1, 0, 0 ), | |
); | |
function is_solved( $arr ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Dashatize it | |
* | |
* @author Phan Vu Hoang <[email protected]> | |
*/ | |
require '../vendor/autoload.php'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function step($g, $m, $n) { | |
$pairs = $primes = []; | |
if ($g >= 2 && $m >=2 && n >= 2) { | |
for ($i=$m; $i <=$n ; $i++) { | |
if (isPrime($i)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* checks if a number is prime | |
* | |
* @return bool | |
* @author Phan Vu Hoang <[email protected]> | |
*/ | |
function la_snt( $n ) { | |
if($n < 2) return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function alphabet_position( $str ) { | |
$str = strtolower( $str ); | |
$alphabetChars = 'abcdefghijklmnoqrstuvwxyz'; | |
$report=[]; | |
foreach (str_split($str) as $char) { | |
$g = (strpos($alphabetChars, $char) !== false) ? strpos($alphabetChars, $char) : ''; | |
if ($g!=='') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Replace With Alphabet Position | |
* | |
* @author Phan Vu Hoang <[email protected]> | |
*/ | |
function alphabet_position(string $str) { | |
$ar_pos = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Convert a multi-dimensional, associative array to CSV data | |
* @param array $data the array of data | |
* @return string CSV text | |
*/ | |
function str_putcsv($data) { | |
# Generate CSV data from array | |
$fh = fopen('php://temp', 'rw'); # don't create a file, attempt | |
# to use memory instead |