This problem is simpler to explain with the code. Note that functions are located in a different file and are being included on the page.
$announcements = $dbc->query($q)->results(); //Returns array of objects
$announcements = prepareMessage($announcements); //Adds html tags to values
$latest = $announcements[0]; //Assign first index to variable
$announcements = truncate($announcements); //Truncate announcement text
function prepareMessage($message) {
foreach($message as $values => $key) {
$key->title = '<h2>'.$key->title.'</h2>';
$key->name = '<p>'.$key->name.'</p>';
$key->date = '<small>'.humanDate($key->date).'</small>';
}
return $message;
}
function truncate($message) {
foreach($message as $values => $key) {
$key->announcement = substr($key->announcement, 0, 50) . '...</p>';
}
return $message;
}
The value of the $latest variable changes after I run this line of code
$announcements = truncate($announcements);
$latest value before that line is ran
[announcement] =>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
$latest value after that line is ran
[announcement] =>
Lorem ipsum dolor sit amet, consectetur adipisc...
So my question is, why is the value of $latest changing?