PHP Sorting array of arrays by 3 fields (gold,silver,bronze)

$arr = array(
Array(
'country_id' => 3,
'country_name' => 'Russia',
'gold' => 23,
'silver' => 21,
'bronze' => 28,
'total' => 72,
),
Array(
'country_id' => 189,
'country_name' => 'USA',
'gold' => 36,
'silver' => 38,
'bronze' => 36,
'total' => 10,
),
Array(
'country_id' => 230,
'country_name' => 'Germany',
'gold' => 16,
'silver' => 10,
'bronze' => 15,
'total' => 41,
),
Array(
'country_id' => 231,
'country_name' => 'China',
'gold' => 51,
'silver' => 21,
'bronze' => 28,
'total' => 100,
)
);

function mySort($a,$b) {
if ($b['gold'] == $a['gold']) {
if ($b['silver'] == $a['silver']) {
if ($b['bronze'] == $a['bronze']) {
return strcmp($b['country_name'], $a['country_name']);
} else {
return $b['bronze'] - $a['bronze'];
}
} else {
return $b['silver'] - $a['silver'];
}
} else {
return $b['gold'] - $a['gold'];
}
}

uasort($arr, 'mySort');
print_r($arr);

Flash Boot Asus Fonepad (FE170CG)

If your device can’t boot or error between booting this will help you ūüôā

Step by Step

1. You need to use ADB tools and fastboot. Download “ADB tools and fastboot” ( Download )

2. Extract it somewhere . Go to “intelandroiddrvsetup1.1.5.zip” and install the drivers.

3. Then Power off your tablet.

4. Hold down the Volume + and Power and release at the Asus logo comes up. ( Now you will see the fastboot menu below of screen)

5. Connect your tablet to your PC.

6. Now go to the folder you extracted the zip file.

7. Press the Shift key and Right click somewhere in the folder. Choose “open command window here”.¬†Then type this commands one by one and press Enter:
fastboot erase cache
fastboot erase system
fastboot erase userdata

8. Download the appropriate firmware from Asus website. ( Download )

9. There are three .img files in the firmware zip file (fastboot.img, boot.img, splashscreen.img). Copy all these three files to the extracted folder. (ADB tools and fastboot folder)

10. Type the following command in the command window one by one:
fastboot flash fastboot fastboot.img
fastboot flash boot boot.img
fastboot flash splashscreen splashscreen.img

11. Put the firmware zip file on your external SD card. Rename it to k012_sdupdate.zip

12. Use the volume keys on you tablet to choose the Recovery (if you have updated to 4.4.2) or SD Update (if your android version was 4.3). Press the Power to choose it. ( The tablet will reboot and flash the firmware)

Than you need to “Deactivation¬†Demo Mode”

13. When a demo Asus showing, Press/Hold [Back key] about 10 sec.

14. Device will show page and enter key pressword [741603] and confirm (The tablet will reboot)

15. Done and Enjoy !!

Function detect mobile device

function mobile_user_agent_switch(){
$device = '';
if( stristr($_SERVER['HTTP_USER_AGENT'],'ipad') ) {
$device = "ipad";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'iphone') || strstr($_SERVER['HTTP_USER_AGENT'],'iphone') ) {
$device = "iphone";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'blackberry') ) {
$device = "blackberry";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'android') ) {
$device = "android";
}

if( $device ) {
return $device;
} else {
return false;
}
}

Sort multidimensional Array by Value

function aasort (&$array, $key) {

 $sorter=array(); $ret=array(); reset($array);

 foreach ($array as $ii => $va) {

  $sorter[$ii]=$va[$key];

 }

 asort($sorter);   ////// asort  (for asc)  or arsort (for desc)

 foreach ($sorter as $ii => $va) {

 $ret[$ii]=$array[$ii];

 }
 
 $array=$ret;

}

aasort($your_array,"order");

Function delete files & folder via PHP

function unlinkRecursive($dir, $deleteRootToo){
 if(!$dh = @opendir($dir)){
  return;
 }
 while (false !== ($obj = readdir($dh))){
   if($obj == '.' || $obj == '..'){
     continue;
   }
   if (!@unlink($dir . '/' . $obj)){
    unlinkRecursive($dir.'/'.$obj, true);
   }
 }
 closedir($dh);
 if ($deleteRootToo){
  @rmdir($dir);
 }
 return true;
}

//// call function
if(unlinkRecursive('insert_full_path','yes')){
 echo 'Successful';
}else{
 echo 'Error';
}