Implicit Evaluation with PHP

Implicit Evaluation with PHP Archives: Arrays

next page ·

22 February 2007

Generating SQL Insert Queries

Its possible to generate a well formed SQL query with one line of PHP by capitalizing on lambda-style functional support.

continue reading... » 2 Comments

23 January 2007

What is $_REQUEST, or the difference between $_REQUEST, $_GET and $_POST

PHP provides you a number of “super-global” variables. These include $_GET, $_POST, $_COOKIE, $_SESSION, $_SERVER, $_ENV, $_FILES and $_REQUEST. Most of these are fairly self-explainatory. $_GET are the variables passed by forms with a GET method or after the end of the path such as example.com/search.php?GETARG1=GETVAL1&foo=bar. $_POST is any variable submitted by a form with […]

continue reading... » One Comment

18 January 2007

Loops in PHP

PHP gives programmers many varieties of loops to work with. Despite an overwhelming selection, each is tailored, really, to just one scenario.

continue reading... » One Comment

1 January 2007

Recursive Data Structures in PHP

Welcome to the Jungle
Today, I was helping a friend implement a recursive category model. There is a top level category and each category contains items and sub-categories.
It’s easy to illustrate on the web:

Top Level Category

Item 1.1
Item 1.2
Subcategory 1.3

Item 3.1
Item 3.2

Subcategory 1.4

Subcategory 4.1

Subcategory 4.1.1

Item 4.1.1.1
Item 4.1.1.2

Item 4.1.2

Somehow, your web browser can take a piece of text […]

continue reading... » 0 Comments

7 December 2006

The Difference Between PHP’s Globals and Superglobals

PHP only has two variable scopes: local and global. But it has three considerations for scoping variables: local, global and superglobal. What exactly is a superglobal?
The only superglobal variables in PHP are

$_POST
$_GET
$_REQUEST
$_COOKIE
$_SERVER
$_SESSION
$_ENV
$_FILES

These are the variables that PHP just gives you which few other languages offer. There is no way to create your own superglobal but […]

continue reading... » 0 Comments

20 November 2006

Comparing array_key_exists With isset

There are two functions for determining the existence of elements in an array: isset and array_key_exists. They are very similar in use, but there are subtle differences.
The biggest difference is speed. array_key_exists takes about 33% longer to execute than isset. For just a few checks, it’s a negligible difference. But in a loop, it will […]

continue reading... » 0 Comments

24 October 2006

Session Management in PHP

Session management is one of the features that sets PHP apart from other languages which happen to be used on the web. It is easy enough to understand how to use $_SESSION, but many programmers seem to learn how to use it and nothing more.
$_SESSION serves a single, useful purpose. It makes variables available across […]

continue reading... » 0 Comments

27 September 2006

Tail Recursion in PHP

There are two types of recursion in the world: tail recursive and non-tail recursive. Non-tail recursive is the more obvious of the two and is used frequently. For instance, when dealing with any kind of hierarchical data (that which is expressed in a tree data structure) a recursive call is likely used to construct the […]

continue reading... » One Comment

26 September 2006

Variable Numbers of Arguments in PHP

There is a problem which infrequently appears in nearly every programming language: calling a function with a variable number of arguments. It is interesting from both sides of development: if you’re writing a function, how will you collect variable numbers of arguments? If you’re consuming a function, how will you provide the arguments?
Much of the […]

continue reading... » 0 Comments

1 May 2006

Accessing Multi-dimensional Array

This weekend, I got an email from a reader wondering how to access non-constant indices of a multidimensional array.
Given an HTML field like <input name=”users[username][email]” type=”text” />
He needed to know how to access it. After trying multiple things, the solution he found was:
$property = “[username][email]”;
$field = $_POST[”users”];
$result = eval (”$field$property;”);
The more obvious $result = […]

continue reading... » 0 Comments

next page ·