Dubz
11-21-2011, 11:24 PM
I'm wondering how i can change a string to an array using a character between.
Something like this:
$string = "tree=papaer|plastic=bottle";
foreach(explode('|',$string) as $variabe){
//Splits it to "tree=paper" and "plastic=bottle" in $variable
//How do i change $variable to '$source => $outcome'?
}
So in the example it would split each part of the string separated with pipes into another string with a looping function (to do for each one). Then it processes that and splits it again with another special character (an equal sign in this case) and splits it into either an array or two separate strings.
Something like this:
$string = "tree=papaer|plastic=bottle";
foreach(explode('|',$string) as $variabe){
//Splits it to "tree=paper" and "plastic=bottle" in $variable
//How do i change $variable to '$source => $outcome'?
}
So in the example it would split each part of the string separated with pipes into another string with a looping function (to do for each one). Then it processes that and splits it again with another special character (an equal sign in this case) and splits it into either an array or two separate strings.