Sorted

Posted Thursday 22nd September, 2005

Sooner or later, whilst using arrays in PHP, you’re going to want to re-order the data. On a one-dimensional array this simply requires us to run one of the sort(), rsort(), asort() or ksort() commands (depending on what we are doing).

However, should we be using a mult-dimensional array, we need to use the array_multisort() PHP command.

If our array is a database result, it is usually a two-dimensional array arranged in rows but array_multisort() sorts using columns. For this reason we need to do some hefty work preparing our array for ordering. Because of this, I ended up writing this short function the other day:

<?php
function do_result_sort($arr_data, $str_column, $bln_desc = false)
{
  $arr_data                 = (array) $arr_data;
  $str_column               = (string) trim($str_column);
  $bln_desc                 = (bool) $bln_desc;
  $str_sort_type            = ($bln_desc) ? SORT_DESC : SORT_ASC;

  foreach ($arr_data as $key => $row)
  {
    ${$str_column}[$key]    = $row[$str_column];
  }

  array_multisort($$str_column, $str_sort_type, $arr_data);

  return $arr_data;
}
?>

This function basically allows me to reorganise a result set array by any column either DESC or ASC (however, only one column at a time - with a little hacking we could change that easily).

Since I’ve found this remarkably useful on occasion, I thought I’d share it with the world…

Update: Just realised that I didn’t give you an example of it in use. Consider that corrected:

< ?php
// Here's an array...
$arr_test = array(array('name' => 'tim', 'veg' => 'carrots'),
                  array('name' => 'rob', 'veg' => 'swede'),
                  array('name' => 'mark', 'veg' => 'brocolli'),
                  array('name' => 'apaul', 'veg' => 'sprouts'),
                  array('name' => 'russell', 'veg' => 'mushrooms'),
                  array('name' => 'stupot', 'veg' => 'leeks'));

// Stick it through our function to sort it...
$arr_test = do_result_sort($arr_test, 'name');
?>

IE Developer Toolbar

Posted Wednesday 21st September, 2005

So Microsoft have finally released a developer toolbar for IE and I’ve just installed it (after a c**king reboot! WTF?).

Unfortunately, although it has some nice features (like the Ruler - love it), it still isn’t as comprehensive as Web Developer for Firefox.

Ah well.

Nice start though Microsoft - I’m afraid there’s quite a lot more for you to do to get us developers back into using your browsers though.

A Night at the Opera

Posted Tuesday 20th September, 2005

The web browser Opera has always been a bit of a niggle with me. It supplies superior options for it’s users as well as some nice advanced accessibility features. Unfortunately, it also featured a nasty banner advert in the top right hand corner of your screen unless you decided to pay a one-off download fee.

However, as of today, that has changed. In a move that will instigate a little competition for the many other free browsers out there (such as Firefox, Safari, Internet Explorer, Netscape etc) Opera has dropped the advert and the download fee.

Get your free Opera here…

Yarrr!

Posted Monday 19th September, 2005

Avast, ye scurvy dogs!

Today be International Talk Like a Pirate day! So get ye swashbuckling acts together ye band of filthy pigs, afore I cut ye gizzards out!

YAAAAAAAAAARRRRRRRRRRRRR!!!

Rentokil Initial 2005

Posted Friday 9th September, 2005

The new Rentokil Initial website has just gone live. It features some nice text-sizing effects using percentages and ems so that the whole site resizes images and all. We’ve also adopted some degradable javascript “print this page” links and some other nice css effects.

Unfortunately, getting content for the site was something of an up-hill struggle but, thankfully, “those-in-power” have finally cottoned on and are working on it as I type.

It’s also worth noting that the content of the site was an ongoing discussion and, therefore, Paul (our main designer guy) had one hell of a task coming up with the design. How do you design without content?

Stylegala have already featured the site (which was coded as part of my day job in the in-house web team at Rentokil, along with Stuart at Muffin Research Labs) and it’s nice to see differing opinions already being published.

Categories:

  1. Accessibility
  2. Agile
  3. Ajax
  4. Apache
  5. API
  6. Architecture
  7. Books
  8. Browsers
  9. CMS
  10. CouchDB
  11. CSS
  12. Design
  13. Development
  14. Django
  15. Email
  16. Events
  17. Gaming
  18. Grammar
  19. Hardware
  20. HTML
  21. HTTP
  22. Humour
  23. Idea
  24. Information Architecture
  25. JavaScript
  26. jQuery
  27. Lean
  28. Life
  29. Linux
  30. Literature
  31. Mac OS X
  32. Management
  33. Meme
  34. Microformats
  35. Monday
  36. MySQL
  37. Networking
  38. News
  39. Personal
  40. Photoshop
  41. PHP
  42. Process
  43. Python
  44. Reference
  45. REST
  46. Science
  47. SEO
  48. Server
  49. Site
  50. Sitepimp
  51. Social
  52. Spelling
  53. Syndication
  54. Testing
  55. The Future
  56. Thoughts
  57. Tools
  58. Tutorial
  59. Tutorials
  60. Typography
  61. UI
  62. UNIX
  63. Virtualisation
  64. Web
  65. Web Standards
  66. Widgets
  67. Wii
  68. Writing
  69. Xbox
  70. XHTML