I know a string like "a b c d" can be put into an array using explode...
But what about something a little more complicated?
"1=5,4=9,6=73,23=12, and so on"
How can we make that into and array that equals...
[1] = 5
[4] = 9
[6] = 73
[23] = 12
String to array
Moderator: General Moderators
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: String to array
Code: Select all
$testString = '1=5,4=9,6=73,23=12';
$testArray = array();
foreach(explode(',',$testString) as $testValue) {
list($discard,$value) = explode('=',$testValue);
$testArray[] = $value;
}
Re: String to array
Thanks!