For the same reason coding style rules/guidelines exist in the first place?
If anybody would pick their preferred style of coding, the syntax would be an utterly mess, with pieces of code using tabs and pieces using spaces for indentation, a mixture of K&R, Allman, maybe Whitesmiths (or any other indent style available, or some invented for the case), etc.
Any of these variants make the code more difficult to read, because any time you encounter some different style, you have to take a break (even only half a second) and switch mentally to that different style, then the time you get two styles mixed together you are doomed.
It's easier to read something like this:
foreach ($data as $var => $val)
{
$type = 'string';
if (in_array($var, $knownInts))
{
$type = 'int';
}
elseif (in_array($var, $knownFloats))
{
$type = 'float';
}
elseif ($var == 'birthdate')
{
$type = 'date';
}
// Doing an increment?
if ($type == 'int' && ($val === '+' || $val === '-'))
{
$val = $var . ' ' . $val . ' 1';
$type = 'raw';
}
// Ensure posts, personal_messages, and unread_messages don't overflow or underflow.
if (in_array($var, array('posts', 'personal_messages', 'unread_messages')))
{
if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
{
if ($match[1] != '+ ')
{
$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
}
$type = 'raw';
}
}
$setString .= ' ' . $var . ' = {' . $type . ':p_' . $var . '},';
$parameters['p_' . $var] = $val;
}
or:
$setString = '';
foreach ($data as $var => $val)
{
$type = 'string';
if(in_array($var,$knownInts)){$type = 'int';}
elseif (in_array($var, $knownFloats)){
$type = 'float';
} elseif ($var == 'birthdate')
$type = 'date';
// Doing an increment?
if ($type == 'int' && ($val === '+' || $val === '-')) {
$val = $var . ' ' . $val . ' 1';
$type = 'raw';
}
// Ensure posts, personal_messages, and unread_messages don't overflow or underflow.
if (in_array($var,
array('posts', 'personal_messages', 'unread_messages'))){
if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
{
if ($match[1] != '+ '){$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';}
$type = 'raw';
}}
$setString .= ' ' . $var . ' = {' . $type . ':p_' . $var . '},';
$parameters['p_' . $var] = $val;
}
You need coding style for the same reason you need a cultural background: easier communication.