View Single Post
ישן 09-05-06, 23:11   # 12
RS324
תודה על תרומתך.
 
מיני פרופיל
תאריך הצטרפות: May 2006
הודעות: 3,173

RS324 לא מחובר  

שילבתי בתוך בדיקות של תקינות וכל מיני שטויות
גם טיפלתי במקרה שהמערך נגמר (הוא פשוט לוקח בחזרה את התמונות שהם DEAFULT
)

בכל מקרה שמתי גם הערות בקוד אז תנסה....


* לא ניסיתי את הקוד *
אני לא חושב שיש דרך יותר טובה לעשות את זה

תהנה

PHP קוד:
function fetch_image_array()
{
    
$file_names[]="icon1.jpg";
    
$file_names[]="icon2.jpg";
    
$file_names[]="icon3.jpg";
    
$file_names[]="icon4.jpg";
    
$file_names[]="icon5.jpg";
    
$file_names[]="icon6.jpg";
    
$file_names[]="icon7.jpg";
    
$file_names[]="icon8.jpg";
    
$file_names[]="icon9.jpg";
    
$file_names[]="icon10.jpg";
    
$file_names[]="icon11.jpg";
    
$file_names[]="icon12.jpg"
}

function 
getimage($array)
{
    
// next line checks if its not array or if array empty if so, get deafult images as array
    
if ((!is_array($array)) OR (sizeof($array) == 0))
    {
        
$array fetch_image_array();
    }
    
$random_image=array_rand($array);
     unset(
$array[$random_image]); 
     
     return array(
     
'myimage' =>$random_image,
     
'oldarray' =>$array
     
);
     
    
}
  
// get the orginal array  
  
$imagefiles =  fetch_image_array();
  
  
// you should do the next lines in for loop
  
  
$info getimage($imagefiles);
  
  
$myimage $info['myimage'];
  
  
$imagefiles $info['oldarray']; // get back the array without the image 
  Reply With Quote