Well, there are many ways to solve this. I'd go with something like this;
$string = "1[abcd] 2[efgh] 3[ijkl]";
$contents = explode(" ", $string);
// We now have $contents with n[...] in each element
$result = array();
$count = 0;
// itterate through the elements
foreach ($contents AS $key => $val) {
// regexp to filter data
preg_match('/([0-9])[(.)]/', $val, $match);
// assign matches to $result
$result[$count]["number"] = $match[1];
$result[$count]["value"] = $match[2];
// increase counter
$count++;
}
And then, we check the output;
foreach ($result AS $k => $v) {
print "$k - num: $v[number], val: $v[value]<br>";
}
Outputs;
0 - num: 1, val: abcd
1 - num: 2, val: efgh
2 - num: 3, val: ijkl
Wich seems good to me 😉
Hope it helped.