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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -