I want to convert to this array
$string = "1,[1,2,3],[2,2,4],2,3"; To Example
0 => 1,
1 => [
0 => 1,
1 => 2,
2 => 3
],
2 => [
0 => 2,
1 => 2,
2 => 4
],
3 => 2,
4 => 3
You can use json_decode() :
$string = "1,[1,2,3],[2,2,4],2,3";
$array = json_decode("[$string]", true);
print_r($array);
Output :
Array
(
[0] => 1
[1] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[2] => Array
(
[0] => 2
[1] => 2
[2] => 4
)
[3] => 2
[4] => 3
)
Above code tested here
dd(json_encode($yourArray));json_decode("[{$string}]")should do it (orjson_decode("[$string]")if you want the shortest version).