Convert key/value string into associated array


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2. * Will turn key=value string into associated array
  3. *
  4. * @param string $str key/value string to convert to array
  5.   * @param string $delim
  6. * @return array
  7. */
  8.  
  9. function explode_to_assoc_array($str,$delim)
  10. {
  11. $result = array();
  12.  
  13. foreach (explode('&', $str) as $couple) {
  14. list ($key, $val) = explode('=', $couple);
  15. $result[$key] = $val;
  16. }
  17.  
  18. return $result;
  19. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.