Jump to content

split values


ngreenwood6

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.