Monthly Archives

March 2010

Code Snippets: PHP Function array_key_match_pullkey

In between all the other projects I’ve been working on (ads, documentation submissions, etc.) I somehow managed to find the time to work on some PHP scripts for a(n) [internal] web-application that I’m responsible for.

There were multiple times where I realized I was doing the same thing again and again in the code, but for different datasets. I needed to find a function in PHP that simply lets you pass a 2+ dimensional Array, a key for the sub-array by which to search for that matches whatever variable you pass, and pulls the value of a separate key in that same sub-array.

Lets look at an example array:

  $smurf = array();

  $smurf[] = array('id' => 12, name => 'Papa Smurf');
  $smurf[] = array('id' => 56, name => 'Brainy Smurf');
  $smurf[] = array('id' => 59, name => 'Smurfette');

At some point I need to be able to pull a Smurf’s name solely by making use of the ID. However, sometimes I may want to do the exact opposite, or do the same kind of info-pull but with a different Array altogether.

So I came up with this today:

// FUNCTION::array_key_match_pullkey()
// ////////////////////////////////////////////////////
// Parameters:
// 1 (array)  : Array : The array to be searched
// 2 (key)    : String: The key we're looking to match
// 3 (match)  : Wild  : The value of the key to match
// 4 (pullkey): String: The key whose value we want to pull
// ////////////////////////////////////////////////////////////////////
// Returns: FALSE or Wild Variable (any type)
function array_key_match_pullkey($array, $key, $match, $pullkey)
   // Begin to loop through array
   foreach ($array as $index)
      // Look in sub-array for matching key/value
      if ($index[$key] == $match)
         // Match has been found, pull the value of the pullkey
         return $index[$pullkey];
   // No match found - return a FALSE boolean value
   return FALSE;

Obviously it would be simplicity itself to modify this function to work with lower level sub-arrays at multiple dimensions, or whatever. I don’t personally need it to do so, and I diddnt feel like spending more than 5 minutes on writing this function. (I usually spend more time on my comments than my code, hah!)

Anyhow, now it is all too easy to pull a smurf ID’d as #59 and find that its Smurfette (the Stephanie of the Smurfs):

$smurf_name = array_key_match_pullkey($smurfs, ‘id’, 59, ‘name’);

This managed to help me chop down the size of my scripts today, and although it may not be the most optimized method (or simplest even); I couldn’t readily find another function (or array operation) that would let me do the same.

Feel free to let me know if you know of some better method, or think up any modifications.

Setup iPhone as Router for Home Network

When visiting my residence up in the northern woods of Michigan, finding any sort of Internet connection (much less some nice cable internet) is a challenge. Unfortunately, the place I have is so deep in the woods, the only recourse would be to set up a ~34 meter tall tower!! (to reach above the 100ft trees) That would net me an 800Mhz wireless connection to a wireless internet company in the area.

Not wanting to spend a couple $1000 just to get some crappy wireless access, I figured out a way to use my iPhone’s internet and patch it through to all of the other computers in the house.

What I Used

  1. Jail-broken 3GS iPhone (3.0 Firmware)
  2. Cisco/Linksys Router (the WRT610N to be exact)
  3. A Computer Running Ubuntu Linux


– Any jail-broken phone that has had Internet Tethering turned on should work

– Any router or switch should work

– Any computer / os combination with routing/masquerading software should work

The iPhone

The iPhone jailbreaking process is (fairly) simple – but you deserve better instructions than I can provide here. I would recommend checking – The Ultimate iPhone News and Guide website.

The Router

Your settings can be whatever happens to suit your needs, however, I personally setup my router to use WPA2/PSK encryption on the 5.0 Ghz range set to Wireless-N for the wireless router. I feel it provides a reasonable level of security and speed. (I also always set a whitelist to allow only the MAC addresses that I want accessing my network.

The router IP address I set to and set the DHCP table for each computer on the network to have its own personal IP address. (, …102, …103, …)

A list of DHCP entries
The 4 Machines on my Network

The Network

On each machine I changed the IP settings to “Manual” settings instead of DHCP (even though I have the DHCP server running on the router .. i know .. i know..) . Obviously this process is done differently on each OS. In my instance the three other machines were WinXP, OSX, and Linux. I made sure each machines IP address matched its corresponding IP in the DHCP table on the router, set the Mask to and the Gateway to 192.168.102 (“Tabasco” .. my personal machine that is connected to the iPhone…

The Real Router

On my computer (an Intel Core-2-Duo 8400 with 4GB RAM running Ubuntu “Karmic Koala”) , I have a USB bluetooth device which I purchased for less than $10. I configured the bluetooth device to act as my computer’s method to connect to the computer. In Ubuntu it was as simple as adding the device through the bluetooth dock item and then clicking on the network dock item and selecting “Connect“. (Obviously you must have Internet Tethering turned on at this point).

The Software

For the routing software I (loosely) followed the directions at the Ubuntu Linux Howto Blog on Setting up Your Computer as a Router. (I just downloaded the Ubuntu compatible .DEB package from Webmin and worked from there).


Overall, I am impressed. The actually speed is nothing to boast about, I’m obviously not in a 4G area (not that the iPhone supports it anyway), nor even a 3G area. That’s right folks, I’m stuck with EDGE speeds. Shockingly (only at night and rarely during the day) I actually manage to achieve speeds of 30KB/s (bytes not bits), which is much better than dial-up. The ping isn’t so great, but that really isn’t a surprise at all.

There are some things to note. When the phone is in “tethering” mode, if a call comes in, the internet connection is disrupted. Completely disconnected in fact. Sometimes when this happens it is difficult and annoying to reconnect the computer to the iPhone. I recommend disconnecting the connection on the computer, turning off bluetooth & internet tethering on the phone. Then turn the internet tethering back on (it will ask you to turn on bluetooth as well, hit OK) and then connect again on the computer.

To solve this problem I went to (on the iPhone) Settings -> Phone -> Call Forwarding and then forwarded my calls to another phone in the house.

I have left the phone connnected for days at a time without disruption and uploaded hundreds of MB of data and downloaded GB’s. All in all, very happy with the results.

What is Social Media Marketing

A friend of mine couldn’t quite put into words what SMM was all about, so I offered to sum it up for him, and sent him this. I thought maybe some of you might likewise be interested in this topic.

Social Media Marketing comes under Internet Marketing:

– ADs (PPC: Pay Per Click, PPI: Pay Per Impression)
– SEO (Search Engine Optimization)
– Social Media Marketing
– Blogs/Vlogs
– Twitter
– Craigslist
– E-Bay

Social Media Marketing can help improve SEO by rote, but the true purpose of SMM is Non-Interruption Based Marketing Strategy (or NIBM). Instead of ads, which annoy people and are by design meant to detract or grab attention when unwanted, SMM‘s purpose is to get people excited about your company and/or product(s) through a Social Medium.

A good example of a Social Medium is Facebook™, with a “Population” of over 400 Million, greater than the population of the United States & Canada combined. Considering that the type of people on Facebook, we are actually talking about a consumer population that easily exceeds that of North America entirely. Over 35 million unique users logon to Facebook every single day.

By making fan pages, or groups on a medium like Facebook, a company can massively increase its popularity. By including games, limited time offers, interaction with the customers (and potential customers) and creating a dialogue with their audience, they end up creating a fan-base. Some corporations are even more popular than many pop-culture icons. This has never happened before in history.

Lets look at a crafty campaign that Burger King™ came up with a couple years ago. Burger King created a Facebook app that would send you a coupon for a free Whopper if you unfriended 10 of your friends for Burger King.

The Whopper Sacrfice Burger King Campaign Logo
Hundreds of thousands were unfriended.. some were even left friendless

This turned out to be a massive success, it was imaginative, original and fun for people to participate in, even those who weren’t particularly fans of burger king. It stirred interest in the company and Burger King made massive profits from an SMM campaign that couldn’t have taken more than a week to design and code and launch.

Even small business’ like bars are creating Facebook accounts and friending customers, people in the area, etc. Take for example the Scotland Yard™ in my hometown of St. Charles, IL with 710 people on its friendslist and growing everyday. They make jokes in their status messages, they comment on peoples activities, photos and give feedback. They of course also remind everyone about special events at the bar. This costs them nothing but some time, and brings back massive return. People love having this kind of relationship. Which bar do you think they are going to go to this Friday night?

Never in business history has it been so easy for companies to reach out to people. Imagine what a company had to do to reach 50,000 people for an ad 100 years ago… it was almost impossible and would have cost dearly. 50 years ago even it was cost prohibitive; Having to run expensive radio ads in multiple cities or even more expensive TV ads.

Don Draper and Kids from Mad Men watching TV in the Living Room
TV Marketing got huge in the 60s as shown in the TV show Mad Men

Even 20 years ago with mail, radio and tv it would’ve have involved many man hours, tons of design and work and had to be budgeted for. Although then you could reach 50 million. Yet it would still take weeks. Now companies can spend 1/1000th of that cost and reach 500 million within the span of 24 hours. This is nothing short of awe-inspiring.

Most companies believe a website is enough. Some even think a website with static content is enough. Very few companies understand the power of Social Media Networks and only a few limited companies throughout the world even have a Social Media person (much less a department) in their Sales/Marketing division.

Think I’m exaggerating? Let’s take a look at my friend Jim who has started and owned several telemarketing companies over the years. Every single one (until the latest iteration, of which I am a part of) was based around the idea of calling people and interrupting them (hence: interruption based marketing).

No one likes to be interrupted.

Yet even so, 30 years ago the close-to-call ratio (closing is a marketing term which is short for “closing a deal“) was surprisingly high with a good “closer“. As the decades have passed with the rise of the do-not-call era, a fundamental shift has occurred in how people respond to telemarketers. The close-to-call ratio has dropped significantly. Now a good closer can hope to get PI or π (you know, 3.14) which is another term for 1 close per 3.14 hours.

Obviously different campaigns differ on expectations, however, overall, it has become obvious that soon the day will come when no-one will answer the phone, and those who do will not buy.

We, as a business society, are barely on the cusp of this new marketing era, and for those who realize its potential now, their place shall be all the much stronger once everyone else wakes up and realizes that interruption based marketing is dead.