Using list() function to swap variables values without adding more variables. $url = 'blog:5'; list($type, $id) = explode(':', $url); // in case that the url is 5:block if (!is_numeric($id)) { list($type, $id) = [$id, $type]; }
/** * Corvert array data to hidden inputs * to pass as form data * * Example: [data => [sub1 => 1, sub2 => 2]] * * * * @author Ivan Gospodinow * @see http://ivangospodinow.com/?p=455 * @param array $array * @param [array | string] $exclude * @return string */ function arrayToHiddenInput(array $array, $exclude = null) […]
Based on this function http://ivangospodinow.com/php-how-to-calculate-system-processors-load-in-percent/ we are getting current cpu load. usleep(1000000 * systemLoadInPercent() / 100); Result: 54.3% cpu load, sleep 0.543 sec
Because that is what php are using in ArrayObject
define('HAS_PRICE', true); define('HAS_NO_PRICE', false); $tries = 0; $won = 0; $wonFirst = 0; $i = 0; $pick = 0; /** * Bottom line, you play against being wrong the first time */ while (++$i
/** * 100 people put a number in box. * every one must find his box within 50 tries */ $allTries = 100000; $usedTries = $allTries; $players = 50; $tries = 25; $settings = []; $people = []; for ($i = 0; $i < $players; $i++) { $settings[$i] = $i; $people[$i] = $i; } $mostPeopleWon […]
1. Open your .htaccess file and add this lines to be bottom. 2. Create your php.error.log file. php_value log_errors 1 php_value error_log ./php.error.log If your file is still empty, add in your php error_reporting(E_ALL); Simple as that
1. Creating Jira issue $jiraUsername = 'Jira login username'; $jiraPassword = 'Jira login password'; $jiraHost = 'http://my-jira-host.com/'; $data = array( 'fields' => array( 'project' => array('key' => 'PR'/* Project Key*/), 'summary'=> 'Issue title', 'description' => 'Some text here, no html tags', 'labels' => array('API', 'IvanGospodinow'/* Put the username so you know which one added it […]
1. Dump structure of the big database. 2. Open the sql file and cut the constraints. 3. Import the structure to another database. 4. Run this code: /** * Sync from live database */ ini_set('memory_limit','512M'); $limit = 100000; $time = time(); $sleep = 1; $sleepEvery = 60; $link = new mysqli( “__HOST__”, “__USER__”, “__PASSWORD__”, “__DATABASE__” […]
$sum = [0, 0, 0, 0]; echo count($sum) / array_sum($sum); // Warning: Division by zero $arraySum = 0.00001 + array_sum($sum); $number = count($sum) / $arraySum; echo round($number, 2); // Result is 0; Just add some small number to the one you are not sure that it will be bigger than zero. Easy as that.