Can be done with explode() and foreach
Steps:
1) First explode the string with new line character
.
2) Loo over it.
3) You will get individual row, explode() it with =
.
4) You will get required key in 0
and value in 1
.
5) Store it in array as key value pair. Done
$str = '1=Books
1.1=Action & Adventure
1.2=Arts, Film & Photography
1.2.1=Architecture
1.2.2=Cinema & Broadcast
1.2.3=Dance';
$arr = explode("
", $str);
$assoc = array();
if (! empty($arr)) {
foreach ($arr as $k => $v) {
$temp = explode('=', $v);
$assoc[$temp[0]] = $temp[1];
}
}
echo '<pre>';print_r($assoc);echo '</pre>';
Output:
Array
(
[1] => Books
[1.1] => Action & Adventure
[1.2] => Arts, Film & Photography
[1.2.1] => Architecture
[1.2.2] => Cinema & Broadcast
[1.2.3] => Dance
)