Alvin Poh

Tag: page

How To Sort A Multidimensional Array By One Element In PHP

I had a table’s worth of listings and had stored all the values in a multidimensional array in PHP. The problem was, I needed to sort the multidimensional array, but based on just one element. Here’s the easiest, fastest solution that I found from the array_multisort function page of PHP (thanks to zequez at gmail dot com!).

Here’s his original solution taken from that page:

$multiArray = Array(
    Array("id" => 1, "name" => "Defg"),
    Array("id" => 2, "name" => "Abcd"),
    Array("id" => 3, "name" => "Bcde"),
    Array("id" => 4, "name" => "Cdef"));
$tmp = Array();
foreach($multiArray as &$ma)
    $tmp[] = &$ma["name"];
array_multisort($tmp, $multiArray);
foreach($multiArray as &$ma)
    echo $ma["name"]."
"; /* Outputs Abcd Bcde Cdef Defg */

My requirements are similar, but not exactly the same, and so I had to tweak the code slightly to fit my needs. I had a huge table of values, but needed to sort the entire multidimensional array by the second column, which was a column of price values. Here’s a simplified version of my tweaked code:

$itemtable = Array(
    Array(1, 253.12),
    Array(2, 569.24),
    Array(3, 85.69),
    Array(4, 91.27));
$tmp = Array();
  foreach($itemtable as &$ma) {
	$tmp[] = &$ma[1]; //this just refers to the 2nd element of my 2-element array
  array_multisort($tmp, $itemtable); 

And that’s it! That’s the fastest, easiest way that I found to sort a multidimensional array, but based on just one element.

How To Split Firefox into Different Windows/Tabs And See Everything At Once

If you work with many websites, or want to keep track of many different websites, and would like to do that simultaneously, then the default Firefox probably wouldn’t cut it for you. Safari has live bookmarks that may do what you want, but in my personal opinion, these following Firefox add-ons do a much better job.

Firefox Splitter (Formerly Split Browser)

Firefox Splitter is an add-on that allows you to browse with multiple tabs open at once in front of you (instead of having just one tab open in the foreground). This would be really useful to watch a video while web browsing, or allowing you to monitor your stock portfolio, or the latest news while you surf the net in another tab.

firefox splitter splitbrowser screenshot


Showcase allows you to manage your current Firefox tabs and windows by showing them as thumbnails in a single window, tab or in a sidebar.

firefox showcase screenshot

Speed Dial

Made by the same people that gave you Showcase, µWorks. Speed Dial gives you the ability to have a home page or tab where you can put your favorite sites, and show a (live) screenshot of every website.

firefox speeddial screenshot

Simple Way to Relay or Pass POST Data From A Page to Another Without .htaccess, Even Cross-Domain

So I had a page which I absolutely could not change or rename. The challenge was, this page would normally receive POST data, and I had to pass or relay this POST data to another page, which resided on another domain. I tried .htaccess, but that didn’t work, so I figured that I had to do some programming. It was simple enough with the curl library to do so, and here it is – The method to pass POST data from page to page:


Copyright © 2016 Alvin Poh

Web Hosting by VodienUp ↑