php tip not to use count in for iteration
Dont use count() in loops because each iteration will count the number of elements; make a variable $count = count($array) and use the variable instead
Dont use count() in loops because each iteration will count the number of elements; make a variable $count = count($array) and use the variable instead
class Newclass { public static function compare($a, $b) { return strcmp($a["name"], $b["name"]); } } usort($array_to_srt, array("Newclass", "compare")); uasort($array_to_srt, array("Newclass", "compare")); The difference between usort and uasort is that uasort keeps the keys, usort resets them and enumerate from scratch.
<?php error_reporting(-1); ini_set(’display_errors’, ‘On’);
1. Objects should be passed by reference always, arrays and scalars are passed by value. 2. If you are working on a very large array and plan on modifying it inside a function, you actually should use a reference to prevent it from getting copied, which can seriously decrease performance or even exhaust your memory […]
<?php $start = (float) array_sum(explode(’ ‘,microtime())); // PHP Database Business Logic $end = (float) array_sum(explode(’ ‘,microtime())); print "Processing time: ". sprintf("%.4f", ($end-$start))." seconds.";
php library: https://github.com/bensquire/php-image-optim png: advpng, optipng, pngout, pngquant, pngcrush jpg: jpegoptim, jpegtran gif: gifscle
1. Directly with Redis class config/app.php … ‘providers’ => array( ‘Illuminate\Redis\RedisServiceProvider’, ), ‘aliases’ => array( ‘Redis’ => ‘Illuminate\Support\Facades\Redis’, ), config/database.php … ‘redis’ => array( ‘cluster’ => false, ‘default’ => array( ‘host’ => ‘127.0.0.1’, ‘port’ => 6379, ‘database’ => 0, ), ), … PHP code will look like this $redis = \Redis::connection(); if ($redis->exists($cacheKey)) { $results […]
error_reporting(-1); ini_set(‘display_errors’, ‘On’);
1. Add trace attribute to SoapClient when intialize it. $soapclient = new SoapClient( $soapurl, array(‘trace’ => 1) ); 2. Add the following 2 methods after making a soap call echo $soapclient->__getLastRequest(); echo $soapclient->__getLastResponse() ;
The usual approach is Use objects when returning a defined data structure with fixed branches: $person -> name = “John” -> surname = “Miller” -> address = “123 Fake St” Use arrays when returning a list: “John Miller” “Peter Miller” “Josh Swanson” “Harry Miller” Use an array of objects when returning a list of structured […]