I am trying to convert a tabbed formatted string into a php array. I attempted to convert each category into separate arrays then preg_match but that did not work out too well.. any suggestions?
Convert:
category 1
subcategory 1
item 1
item 2
subcategory 2
item 1
item 2
subcategory 3
item 1
item 2
category 2
subcategory 1
item 1
item 2
subcategory 2
item 1
item 2
category 3
subcategory 1
item 1
item 2
item 3
item 4
To:
$data = [
'category 1' =>[
'subcategory 1' =>[
'item 1',
'item 2'
],
'subcategory 2' =>[
'item 1',
'item 2'
],
'subcategory 3' =>[
'item 1',
'item 2'
]
],
'category 2' =>[
'subcategory 1' =>[
'item 1',
'item 2'
],
'subcategory 2' =>[
'item 1',
'item 2'
]
],
'category 3' =>[
'subcategory 1' =>[
'item 1',
'item 2',
'item 3',
'item 4'
]
]
];