Archive for May, 2009

To reset the key values in a PHP array you can do this:
1234567891011121314151617181920212223$things = array(’a',’b',’c',’d');
unset($things[0]);
print_r($things);

#outputs
#Array
#(
#    [1] => b
#    [2] => c
#    [3] => d
#)

# Actually do the reset.
$things = array_values($things);

print_r($things);
#outputs
#Array
#(
#    [0] => b
#    [1] => c
#    [2] => d
#)

Ran into an interesting situation yesterday. I wanted to create some dynamic (overloading) object attributes (object member variables) in PHP with private visibility. Forcing encapsulation via getter methods. It seems this is not possible, as dynamic attributes are only ever public (see the PHP documentation).
There is however, as always, a work around! If you [...]


top