adam291086 Posted March 11, 2009 Share Posted March 11, 2009 i have this array Array ( [username] => l [password] => h [title] => [forename1] => kjhkjh [forename2] => kjhk [surname] => kjhkjhkjh [addressLine1] => [addressLine2] => [town] => [postcode] => [secondEmail] => [personalUrl] => [postcodeStart] => [authorityToWorkStatement] => [contactPreference] => Mobile [EducationLevels_idEducationLevel] => [noOfGcses] => 000 [gcseEnglishGrade] => [gcseMathsGrade] => [noOfAlevels] => 0000 [ucasPoints] => 0000 [studentStatus] => Full-time [mobile] => [landline] => [dob] => Array ( [MONTH] => [DAY] => [YEAR] => ) [penaltyPoints] => ) i need to take dob array and join the month, day and year values and join them together yyyy/mm/dd and put it back into the array for example Array ( [username] => l [password] => h [title] => [forename1] => kjhkjh [forename2] => kjhk [surname] => kjhkjhkjh [addressLine1] => [addressLine2] => [town] => [postcode] => [secondEmail] => [personalUrl] => [postcodeStart] => [authorityToWorkStatement] => [contactPreference] => Mobile [EducationLevels_idEducationLevel] => [noOfGcses] => 000 [gcseEnglishGrade] => [gcseMathsGrade] => [noOfAlevels] => 0000 [ucasPoints] => 0000 [studentStatus] => Full-time [mobile] => [landline] => [dob] => 2000/10/27 [penaltyPoints] => ) i have no idea how to go about this can some push me in the right direction Link to comment https://forums.phpfreaks.com/topic/148916-solved-array-help/ Share on other sites More sharing options...
jcombs_31 Posted March 11, 2009 Share Posted March 11, 2009 How is the array populated to begin with? Link to comment https://forums.phpfreaks.com/topic/148916-solved-array-help/#findComment-781947 Share on other sites More sharing options...
adam291086 Posted March 11, 2009 Author Share Posted March 11, 2009 its basically just all the $_POST variables print_r($_POST); Link to comment https://forums.phpfreaks.com/topic/148916-solved-array-help/#findComment-781950 Share on other sites More sharing options...
kickstart Posted March 11, 2009 Share Posted March 11, 2009 Hi Can you not just (assuming the array is called $fred):- $fred['dob'] = $fred['dob']['YEAR']."/".$fred['dob']['MONTH']."/".$fred['dob']['DAY']; Although would be tempted to avoid doing that to the $_POST array (ie, copy the bits of that array elsewhere to play with). All the best Keith Link to comment https://forums.phpfreaks.com/topic/148916-solved-array-help/#findComment-781952 Share on other sites More sharing options...
adam291086 Posted March 11, 2009 Author Share Posted March 11, 2009 Well this is a uni project and we need to make it so that anyone can add fields into that database and the forms will automaticalyy up date. so i am using this function to generate an insert query function mysql_insert_array($table, $data) { foreach ($data as $field=>$value) { $fields[] = sprintf("`%s`", $value); } $field_list = join(',', $fields); $query = sprintf("INSERT INTO `%s` VALUES %s ", $table, $field_list); return $query; } hence the reason i use $_POST array so that all the form info will update automatically as the input field names ect = the names within the database table. Link to comment https://forums.phpfreaks.com/topic/148916-solved-array-help/#findComment-781955 Share on other sites More sharing options...
jcombs_31 Posted March 11, 2009 Share Posted March 11, 2009 So do you plan to have 2 arrays? I don't quite understand why you can't just concatenate the date fields. Link to comment https://forums.phpfreaks.com/topic/148916-solved-array-help/#findComment-781961 Share on other sites More sharing options...
adam291086 Posted March 11, 2009 Author Share Posted March 11, 2009 if i concatenate the data fields which is possible how would i go about create one array from the $_POST array and the new concatenated variable Link to comment https://forums.phpfreaks.com/topic/148916-solved-array-help/#findComment-781963 Share on other sites More sharing options...
adam291086 Posted March 11, 2009 Author Share Posted March 11, 2009 i solved it by doing $date = $_POST['dob']['YEAR']."-".$_POST['dob']['MONTH']."-".$_POST['dob']['DAY']; $test = array(); foreach ($_POST as $key => $value) { if ($key == 'dob') { $test[$key] = $date; continue; } else { $test[$key] = $value; } } Link to comment https://forums.phpfreaks.com/topic/148916-solved-array-help/#findComment-781975 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.