Skip to content

Instantly share code, notes, and snippets.

@henrytran9x
Created July 21, 2017 06:44
Show Gist options
  • Save henrytran9x/f654b54ed85868153fe05ba3fccce05b to your computer and use it in GitHub Desktop.
Save henrytran9x/f654b54ed85868153fe05ba3fccce05b to your computer and use it in GitHub Desktop.
ConvertStringToArray
<?php
public function ConvertStringToArray($str) {
$str = substr($str, 1, strlen(substr($str, 0, strlen($str)-2)));
$str = str_replace("'",'',$str);
$strs = explode(',', $str);
$arr = array();
$c_strs = count($strs);
for ($i = 0; $i < $c_strs; $i++) {
if (strpos($strs[$i],'=>') !== false) {
$_arr = explode('=>',$strs[$i]);
$arr[trim($_arr[0])] = trim($_arr[1]);
}
}
return $arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment