I need to change it to:
$arr['id']=1; $arr['type']=2;
Usage: parse_str () .
void parse_str(string $str [, array &$arr])
Parses str, as if it is a query string passed through a URL, and sets the variables in the current scope.
Example:
<?php $str = "first=value&arr[]=foo+bar&arr[]=baz"; parse_str($str); echo $first; // value echo $arr[0]; // foo bar echo $arr[1]; // baz parse_str($str, $output); echo $output['first']; // value echo $output['arr'][0]; // foo bar echo $output['arr'][1]; // baz ?>
Assuming you want to parse what looks like a query string, just use parse_str():
parse_str()
$input = 'id=1&type=2'; $out = array(); parse_str($input, $out); print_r($out);
Output:
Array ( [id] => 1 [type] => 2 )
, parse_str() . . , . , register_globals() .
register_globals()
See parse_str.
parse_str
$arr = array(); $values = explode("&",$string); foreach ($values as $value) { array_push($arr,explode("=",$value)); }
Use parse_str()with the second argument , for example:
$str = 'id=1&type=2'; parse_str($str, $arr);
$arr will contain:
$arr
Source: https://habr.com/ru/post/1728403/More articles:SWFobject - how to automatically redirect - actionscript-3Mail server integration in Java EE application - java42 passed to TerminateProcess, sometimes GetExitCodeProcess returns 0 - cHow can I access / change request headers / reponses on a DataSnap Delphi 2010 server - httpURLRequest with DELETE Method - flexIndividually execute all files in a directory - bashHow to find all types of dependencies of a certain type in any CLR-based language assembly? - c #WCF service debugging caused by a Windows service in C # - c #Storage Algorithm Question - Testing Sequential Data with Small Memory - optimizationEliminate the need for a “controller” in the Zend Framework controller file name - phpAll Articles