I am sorry I can't explain this, but I simply can't 🙁
This is what I want to do, consider this:
$_POST['agencies'] = array('abc', 'def', 'xyz');
Ok you have a form with like checkboxes or whatever that you enter more than one item.
I want to convert
$_POST['agencies']
into
$POST['agencies_bundle'] = $POST['agencies'][0] . $delimiter . $POST['agencies'][1] . $delimiter . $POST['agencies'][2]
Ok, I hope you got that so far, that's what I'm trying to do. Now I thought of using either array_walk() or usort() or whatever to accomplish this but saving time by bundling $_POST fields into an array itself. This is to save on long lines of code to make it more elegant.
The problem is that my methods produce the following:
$_POST['agencies_bundle'] = '' when it should be 'abc,def,xyz'
Basically, what did I do wrong?
Thanx
Phil
class ActionPerformer extends InternsActionPerformer {
/**
* Edit existing intern. Will be void method with no functionality to use as redirect to db
*
* *NOTE* This method will override InternsActionPerformer::edit() method intentionally to allow for usage of specific code
*
* @access public
*/
function &edit() { // STATIC VOID METHOD
global $section, $redirectArray, $projectAcronym;
$bundleArray = array('internship_time', 'agencies', 'internship_time', 'internship_area');
usort($bundleArray, array($this, 'bundle'));
print_r($_POST); die('');
if ($this->isSuccessful) unset($_SESSION["${projectAcronym}_mainDisplay"]);
if ($this->isSuccessful && $redirectArray[$section]['edit']) echo $this->getHTMLRedirect('edit', '&willFlushResult=1');
}
}
class InternsActionPerformer extends DBActionPerformer {
/**
* Bundle together $_POST array items into a single string tagged with "_bundle" to distinguish from original $_POST array key name
*
* @access protected
* @param mixed $field
* @param mixed $delimiter
*/
function &bundle($field, $delimiter) { // STATIC VOID METHOD
print_r("field = $field and delimiter = $delimiter<P>");
${$field} = $_POST[$field];
print_r("<P>field = $field = "); print_r(${$field}); print_r("<P>");
$max = (@in_array('**OTHER**', ${$field})) ? @array_search('**OTHER**', ${$field}) : (@sizeof(${$field}) - 1);
print_r("max = $max<P>");
if ((int)$max > 0 && @in_array('**OTHER**', ${$field})) ${$field . "[$max]"} = 'other'; // RE-INSERT "other" INTO BUNDLE
for ($i = 0; $i < @sizeof(${$field}); $i++) $bundle .= ${$field . "[$i]"} . $delimiter;
if ($_POST["${field}_other"]) $bundle .= $_POST["${field}_other"];
$bundle = substr($bundle, 0, strrpos(trim($bundle), $delimiter));
$_POST["${field}_bundle"] = $bundle; // ADD TO $_POST
}
}