Being able to accept parameters into your scripts with argc and argv is good enough for some people, but if you run on Unix there's an even better way: the getopt() function. With getopt() you just tell it what parameters your script is able to accept, and it does the rest.
That code tells getopt() to read in three parameters from the command line: -a, -b, and -c. If any of these are specified, they are placed into the array return value. Those that are not specified are simply left out of the array. Any extra parameters that were passed that aren't listed get ignored.
Note that I've changed the parameter passed to getopt() - there are now two colons in there, and we also accept a "d" parameter. What the two colons do is say that the parameter before expects to get some value attached to it. So, we can now call the script like this:
php getopt -a -b hello -d world
This time we only get "false" an array value when there was no value passed:
There is one potential gotcha here, and that's the fact that the function isn't smart enough to allow optional values. Try calling the script like this:
php getopt -a -b -d world
There is a second parameter you can pass to getopt(), which is an array specifying the names of long parameters (that is, --foo rather than just -f) to accept. Sadly the functions behind it only work on a small number of systems; my test Linux boxes didn't work at all!