<?php
$i = 0;
while($i < count($names)) {
echo "<li>"
echo "<div class = \"avatar\">;
<img src=\"images/user.png\">;
</div>";
echo "<h2>" . $names[$i] . "</h2>";
echo "<p>Привет!</p>";
echo "<div class = \"time\">09:15</div>";
echo"</li>";
$i = $i + 1;
}
?>
<?php $names=['петя','вася']; ?>
<?php if ($names): ?>
<ul>
<?php foreach ($names as $name): ?>
<li>
<div class = "avatar">
<img src="images/user.png">
</div>
</li>
<h2><?=$name?></h2>
<p>Привет!</p>
<div class = "time">09:15</div>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php
$i = 0;
while($i < count($names)) {
echo "<li>"; //Здесь не было ;
echo "<div class = \"avatar\">
<img src=\"images/user.png\">
</div>";
echo "<h2>" . $names[$i] . "</h2>";
echo "<p>Привет!</p>";
echo "<div class = \"time\">09:15</div>";
echo"</li>";
$i = $i + 1;
}