Thread: Array mess
View Single Post
Old 12-13-2008, 01:00 AM   #4 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

If you're willing and/or able to use some of the SPL features then you code could be whittled down to something like the following (just an example off the top of my head).

PHP Code:
class Parameters extends ArrayObject {
    
    public function 
__construct($string)
    {
        
$string str_replace(',''&'$string);
        
parse_str($string$data);
        
$this->exchangeArray($data);
    }
    
}

$string 'something=test,this=that';
$params = new Parameters($string);
// Can use array syntax, or offsetGet method
var_dump$params['this'] ); 
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
KingOfTheSouth (12-13-2008)