0

when run var_dump($myVariable) I have this string, this variable is not json :

string(13) "['1','2','3']"

but I want have this:

array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" }

how can I convert $myVariable to second format

nima amiri
  • 21
  • 4

1 Answers1

2

If the string you are converting is consistent, the following isn't tested, but you can do something like the following:

$string = "['1','2','3']";
$string = str_replace(['[','\'',']'], '', $string);
$array = explode(',', $string);
user3720435
  • 1,421
  • 1
  • 17
  • 27