在PHP中处理字符串

Rya*_*yan 1 php arrays

我需要一种方法来排序我在PHP中的字符串,字符串格式如下,但更大.

{ 1, 3, 1, 2, }, { 2, 3, 2, 1, }, { 3, 3, 2, 2, }, { 1, 2, 3, 1, },
Run Code Online (Sandbox Code Playgroud)

我需要它做的是将括号中的每组数字转换为数组.因此,在这种情况下,将有四个数组,每个数组中有四个值.

第一个数组如下所示:

array1[0] == 1
array1[1] == 3
array1[2] == 1
array1[3] == 2
Run Code Online (Sandbox Code Playgroud)

我怎么能做到这一点?

Sea*_*ght 20

$inbound = "{ 1, 3, 1, 2, }, { 2, 3, 2, 1, }, { 3, 3, 2, 2, }, { 1, 2, 3, 1, }";
$inbound = trim(preg_replace("/,\\s*}/i", "}", $inbound), " ,");
$inbound = str_replace("{", "[", $inbound);
$inbound = str_replace("}", "]", $inbound);

$array_of_arrays = json_decode('[' . $inbound . ']');
Run Code Online (Sandbox Code Playgroud)