Topics
Dates
200902 · 05 · 06
2008
01 · 02 · 03 · 04 · 07 · 08 · 09 · 11
2007
06 · 07 · 08 · 09 · 10 · 11 · 12
Also check out FishoftheBay.com for more thoughts about design and life.
PHP Arrays
PHP July 19, 2007
PHP hashmap-style arrays make a great solution to wanting to pass multiple variables but not wanting to specify them all in the arguments to a function.
As far as object-oriented stuff goes, you can specify an array of properties (pun intended?) and pass them all via one variable.
The nice thing is, if your function or object is expecting certain properties and you format your array properly, you can get a lot out of your array.
For example, making an object entirely based on an array you pass it can be wonderful when you write your object once (and yeah it will be complicated) but whenever you want to create new instances of it, with all the same functionality and display style, you probably only need to write a few more lines of code.
$fields = array (
"table_name" => "users",
"table_order" => "userID",
"dependence" => array (
"table_name" => "posts",
"table_order" => "postID"
)
)
$editable = array (
"Name" => array (
"type" => "text",
"required" => true
"db_field" => "username"
)
)
Something like the above code could generate a very complicated webpage, if you code it properly ;^)
Other PHP Posts
Always Coding Generically
I've been programming websites for a while now and though I often do things fast for prototyping purposes, I find myself wishing I coded in a more generic manner. Sure, it's easy to go ahead and write the code as you ...
Using PHP When Possible
In recent months, I've gotten in the habit of writing things in PHP arrays, using a function with a loop to actually generate HTML. This works great for anything where you have repeating elements (such as a table, lists,...
Processing Forms: Javascript or PHP?
I've dealt with a lot of online forms. Most, on submit, will refresh the page and process the data before the page loads. Then it will tell you of any errors you have. Sometimes, a page reload can take a while. If yo...