1
我想將嵌套括號轉換爲包含關鍵字的數組。下面是模式:如何通過正則表達式將字符串分解爲數組元素?
preg_match_all('/(?=\{((?:[^{}]++|\{(?0)\})++)\})/', $string, $res);
和數據需要分析:
employee {
cashier { salary = 100; }
technician { age = 44; }
}
結果,我需要:
Array
(
[employee] => Array (
[0] => Array
(
[cashier] => Array
(
[salary] => 100
)
)
[1] => Array
(
[technician] => Array
(
[age] => 44
)
)
)
)
,但不能迭代內嵌套的括號內。困在這裏。在此先感謝您的幫助
'preg_split'可能更合適 – RamRaider