php - Weird behavior of callback function -


i need parse parameter string becomes array. here code:

$paramstr = 'type,mp3|path,audio/file.php?id=artist01|popup,yes';  function parse($paramstr) {     $params = preg_split('#=|,|\|#', $paramstr);     ($i=0;$i<count($params);$i+=2) {         if ($params[$i] == "path") {             $params[$i+1] = $baseurl . "/" . $params[$i+1];         }         $ret[$params[$i]] = $params[$i+1];     }     return $ret; }  if ($paramstr != "") {     $paramarr = parse($paramstr); } else {     echo 'error'; } 

when var_dump($ret), output correct:

array   'type' => string 'mp3' (length=3)   'path' => string 'http://localhost/audio/file.php%3fid%3dartist01' (length=49)   'popup' => string 'yes' (length=3) 

however, when var_dump($paramarr), got weird output:

array   'type' => string 'mp3' (length=3)   'path' => string 'http://localhost/audio/file.php?id' (length=34)   'artist01' => string 'popup' (length=5)   'yes' => null 

anyone knows why? in advance.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -