Hellow.
i have a string output. "zoneAdd[1][home][group]"
I need.
$task = "ZoneAdd"
$id = 1
$place = "home"
$type = "group"
How to spit these guys? I need a PHP or javascript solution.
Here's one way with Javascript. You can split the string using regex. It can output an array and from there you can loop and assign the strings to the variables you need
const str = "zoneAdd[1][home][group]"
const strArr = str.replace(/[\[\]']+/g,' ').trim().split(' ')
const task = strArr[0]
const id = strArr[1]
const place = strArr[2]
const type = strArr[3]
console.log({strArr, task, id,place,type})
Here is the PHP solution if you want to split without regex
<?php
$string="zoneAdd[1][home][group]";
$arr=explode("[", $string);
foreach ($arr as $key=>$item) {
$arr[$key]=explode("]", $item)[0];
}
$task=$arr[0];
$id=$arr[1];
$place=$arr[2];
$type=$arr[3];