Posts by Tag "Snippets"

Subscribe to posts of this tag

Multidimensional Array via SPL

Per default any implementation of ArrayObject does not allow to use the object as multidimensional array. This snippet here implements the support:
class ArrayMultiObject extends ArrayObject
{
    function __construct($array, $flags = 0, $iterator_class = "ArrayIterator")
    {
        $objects = array();
        foreach($array AS $key => $value) {
            if(is_array($value)) {
                $objects[$key] = new ArrayMultiObject($value, $flags, $iterator_class);
            } else {
                $objects[$key] = $value;
            }
        }
 
        parent::__construct($objects, $flags, $iterator_class);
    }
 
    public function offsetSet($name, $value)
    {
        if(is_array($value)) {
            $value = new ArrayMultiObject($value);
        }
 
        return parent::offsetSet($name, $value);
    }
}

Linux style MySQL Shell prompt

Just add the following to the [mysql] section in your .my.cnf file:
prompt=\u@\h [\d]>\

Zend_View Hack for implementation of RSS Feed

Using Zend_View for your site and want to implement an RSS Feed? You might run into the problem that the XML header definition is interpreted as PHP code:
<?xml version="1.0" encoding="ISO-8859-1"?>
Before you start cursing the world try this (rather obvious) workaround:
<?php echo '<?xml version="1.0" encoding="ISO-8859-1"?>'; ?>