Sort By State - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Sort By State.php

  1.  
  2. <?php
  3.  
  4. $omni = array(
  5.     array(
  6.         'id' => 17760,
  7.         'name' => array(
  8.             'long' => 'Omni Military Loans in Columbus, GA.',
  9.             'abbv' =>'Columbus, GA'
  10.             )
  11.         ),
  12.     array(
  13.         'id' => 21037,
  14.         'name' => array(
  15.             'long' => 'Omni Military Loans in El Paso, TX.',
  16.             'abbv' =>'El Paso, TX'
  17.             )
  18.         ),
  19.     array(
  20.         'id' => 21040,
  21.         'name' => array(
  22.             'long' => 'Jacksonville, FL',
  23.             'abbv' =>'Jacksonville, FL'
  24.             )
  25.         ),
  26.     array(
  27.         'id' => 21040,
  28.         'name' => array(
  29.             'long' => 'Omni Military Loans in Hinesville, GA.',
  30.             'abbv' =>'Hinesville, GA'
  31.             )
  32.         )
  33. );
  34. function compare($a, $b)
  35. {
  36.     return strcmp(substr($a["name"]["abbv"],-2), substr($b["name"]["abbv"],-2));
  37. }
  38.  
  39. usort($omni, "compare");
  40. print_r($omni);
  41.  
File Description
  • Sort By State
  • PHP Code
  • 24 Jun-2021
  • 891 Bytes
You can Share it: