$result = array();
parse_str($_REQUEST['InventoryData'], $data);
foreach ($data as $key => $value) {
$result[] = array($key, $value);
}
Convert a string into list of arrays
Pregunta
How do I convert a REQUEST string into arrays in a list like the following?
$_REQUEST["InventoryData"] == sku=qty&234444=11&ShirtBig=111&ShirtSmall=101&empty=0
Array ( [0] => sku [1] => qty )
Array ( [0] => 234444 [1] => 11 )
Array ( [0] => ShirtBig [1] => 111 )
Array ( [0] => ShirtSmall [1] => 101 )
Array ( [0] => empty [1] => 0 )
This is a modification of "MASS UPDATE STOCK LEVELS IN MAGENTO – FAST" script for updating using a client side submission of data.
Solución
Otros consejos
You could use the explode function to split strings into arrays by a certain character: http://php.net/manual/en/function.explode.php
However you may need to do some string manipulation to get that string into the structure you posted.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow