Ad
Php : Convert Serialized To Array
I have a form sending a post request to server . there is a hidden input in form containing a serialized string value :"menuItem[2]=null&menuItem[4]=2&menuItem[6]=4&menuItem[5]=2&menuItem[7]=null&menuItem[3]=null"
I'm trying to convert this string to an array using php:[ 2 => null, 4 => 2, 6 => 4 , ...]
is there any neat way to do that?
Ad
Answer
You can just use parse_str.
parse_str('menuItem[2]=null&menuItem[4]=2&menuItem[6]=4&menuItem[5]=2&menuItem[7]=null&menuItem[3]=null', $arr);
var_dump($arr);
Will result in:
array (
'menuItem' =>
array (
2 => 'null',
4 => '2',
6 => '4',
5 => '2',
7 => 'null',
3 => 'null',
)
)
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad