Php - convert string to array -


i have array in string :

"[14,16,18]" 

i want remove double quotation , result :

[14,16,18] 

i've tried :

   $restaurantids =request::all();     dd(trim(array_values($restaurantids)[0], '"'),array_values($restaurantids)[0] , $restaurantids)  ; 

and result :

"[14,16,18]" "[14,16,18]" array:1 [   "restaurant" => "[14,16,18]" ] 

any suggestion?

you can below:-

<?php  $string = "[14,16,18]";  $array = json_decode($string, true); print_r($array); 

output:- https://eval.in/847737

another solution:-

<?php  $string = "[14,16,18]";  $array = explode(',',str_replace(array('[',']'),array('',''),$string));  print_r($array); 

output:-https://eval.in/847734


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -