Are you thinking about this..... for refreshing you have to use session variables
<?php
session_start();
if(!isset($_session['a']))
$_session['a'] = 1;
$a = $_session['a']; // retrieves the value even you refreshes the page
$i=3;
while(1){
$images[$a] = ("$appear");
$a = $a + 1;
if($a>3)
$a=1;
$_session['a'] = $a; //stores the value even you refreshes the page
}
?>
it will reset the $a value to 1 when it reaches 3 If is this you are looking for..?