ngreenwood6 Posted October 29, 2009 Share Posted October 29, 2009 I have values that are returned to me in this format: name=>test,age=>49 What I want to get out of this is an array like this array('name'=>'test','age'=>'49'); I was hoping some one could let me know the best way to do this. I was thinking about using preg_split() but wasnt sure if it was the best method. Also not that good with regex. Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/179453-split-values/ Share on other sites More sharing options...
WolfRage Posted October 29, 2009 Share Posted October 29, 2009 <?php $array=explode(',',$inPutString); $array2=array(); foreach($array as $key){ $parts=explode('=>',$key); $array2[$parts[0]]=$parts[1]; } var_dump($array2); ?> That should do the trick my friend, but I did not test the code just typed from memory so be sure to fix any errors or report them back here and I will fix them. Link to comment https://forums.phpfreaks.com/topic/179453-split-values/#findComment-946844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.