Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 878 Bytes

0625.md

File metadata and controls

36 lines (29 loc) · 878 Bytes

What is the best approach for converting this string:

$string = "a=10&b[]=20&c=30&d=40+50";

// Into this array?

array(- [ ] {
      ["a"]=>
      string(- [ ] "10"
      ["b"]=>
      array(- [ ] {
        [0]=>
        string(- [ ] "20"
      }
      ["c"]=>
      string(- [ ] "30"
      ["d"]=>
      string(- [ ] "40 50"
}
  • A) Use the parse_str() function to translate it to an array()
  • B) Write a parser completely by hand, it's the only way to make sure it's 100% accurate
  • C) Pass the variable to another PHP script via an HTTP GET request and return the array as a serialized variable
  • D) Just call unserialize() to translate it to an array()
Answer

Answer: A