10 PHP Tricks for Associative Array Manipulation
Dec 11, 2010, 07:03 (0 Talkback[s])
(Other stories by W. Jason Gilmore)
Re-Imagining Linux Platforms to Meet the Needs of Cloud Service Providers
"The associative array -- an indispensable data type used to
describe a collection of unique keys and associated values -- is a
mainstay of all programming languages, PHP included. In fact,
associative arrays are so central to the task of Web development
that PHP supports dozens of functionsand other features capable of
manipulating array data in every conceivable manner. Such extensive
support can be a bit overwhelming to developers seeking the most
effective way to manipulate arrays within their applications. In
this article, I'll offer 10 tips that can help you shred, slice and
dice your data in countless ways.
"1. Adding Array Elements
"PHP is a weakly typed language, meaning you're not required to
explicitly declare an array nor its size. Instead you can both
declare and populate the array simultaneously:
$capitals = array(
'Alabama' => 'Montgomery',
'Alaska' => 'Juneau',
'Arizona' => 'Phoenix'
"Additional array elements can be appended like this:"