private static function getOrdering($sortingColumn, $sortingDirection)
{
if ($sortingColumn === 'reportTime') {
return implode(', ', array_map(function ($column) use ($sortingDirection) {
return $column . ' ' . $sortingDirection;
}, ['report_date', 'report_hour', 'report_minute']));
}
return $sortingColumn . ' ' . $sortingDirection;
}
I'm struggling a bit to understand how the combination of implode and array_map are working. Moreso, what exactly does array_map(function ($column) use ($sortingDirection)...
mean? The function ($column) (what does this mean, and where does column come from?) is throwing me off a bit. I'm quite new to PHP, so any basic explanation will likely help.
Edit: Apologies. This is far too broad. Perhaps a more pointed question is: I did try something, but I'm wondering why in the case that the sortingColumn is "reportTime", we don't simply return a concatenation of the "report_date", "report_hour", etc along with the sortingDirection appended to each. Running:
$sortingDirection = 'DESC';
echo(implode(' , ', array_map(function ($column) use ($sortingDirection) { return $column . ' ' . $sortingDirection;}, ['report_date', 'report_hour', 'report_minute'])));
gives me what I'd think: report_date DESC, report_hour DESC, etc. Why go through the extra steps of implode, array_map, etc when I could just return the appropriate string right from the start?