note 79799 deleted from function.explode by tularis

From: Date: Mon, 27 Oct 2008 13:04:27 +0000
Subject: note 79799 deleted from function.explode by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-145814@lists.php.net to get a copy of this message
Note Submitter: Saurabh Sahni ---- An extension to explode can be explode_assoc. This is reverse of implode_assoc return by Brian and can be found with implode. <?php function explode_assoc($glue1, $glue2, $array) { $array2=explode($glue2, $array); foreach($array2 as $val) { $pos=strpos($val,$glue1); $key=substr($val,0,$pos); $array3[$key] =substr($val,$pos+1,strlen($val)); } return $array3; } //usage: $str="key1=val1&key2=val2&key3=val3"; $array=explode_assoc('=','&',$str); print_r($array); ?> This outputs: Array ( [key1] => val1 [key2] => val2 [key3] => val3 )

« previous php.notes (#145814) next »