Simple array question in PHP -
not sure if there built in function this, thought ask before waste time of writing one. lets have array:
array ( ['first_name'] => john ['last_name'] => doe ['ssn1'] => 123 ['ssn2'] => 45 ['ssn3'] => 6789 )
how can create new key ['ssn']
combine values of other three, result in following:
array ( ['first_name'] => john ['last_name'] => doe ['ssn'] => 123456789 )
it comes in separated because there 3 separate inputs such [ ]-[ ]-[ ]
keep user screwing up. so, effective/elegant way of doing this? thanks!
edit
looks came same simple solution. have give first. everyone!
assuming data comes web form, use input naming convention advantage. name elements in order first_name, last_name, ssn[1], ssn[2], ssn[3]. $_request automatically assign 3 elements structured array.
<input type="text" name="ssn[1]" /> <input type="text" name="ssn[2]" /> <input type="text" name="ssn[3]" /> array 'ssn' => array 1 => string '123' (length=3) 2 => string '456' (length=3) 3 => string '7890' (length=4)
then can
$_post['ssn'] = implode('-', $_post['ssn']);
simple , clean.
Comments
Post a Comment