Help with PHP Array code -
hey guys! need writing code creates array in format needed in. have long string of text -> "settings=2&options=3&color=3&action=save"...etc next thing did make array following:
$form_data = explode("&", $form_data);
ok far good...i have array so:
array ( [0] => settings=2 [1] => options=3 [2] => color=3 [3] => action=save ) 1
ok need know how 2 things. first, how can remove occurences of "action=save" array?
second, how can make array become key value pair (associative array)? "settings=>2"?
thanks...
there's a function that. :)
parse_str('settings=2&options=3&color=3&action=save', $arr); if (isset($arr['action']) && $arr['action'] == 'save') { unset($arr['action']); } print_r($arr);
but reference, manually this:
$str = 'settings=2&options=3&color=3&action=save'; $arr = array(); foreach (explode('&', $str) $part) { list($key, $value) = explode('=', $part, 2); if ($key == 'action' && $value == 'save') { continue; } $arr[$key] = $value; }
this not quite equivalent parse_str
, since key[]
keys wouldn't parsed correctly. i'd sufficient example though.
Comments
Post a Comment