Question

Excuse me. I am beginner for this code web :)

I have 3 images for my banner...
I dont want appear image banner same as random() statement
I have tried an array multidimensional php

$images[0] = ("1.jpg","2.jpg","3.jpg");
$images[1] = ("2.jpg","3.jpg","1.jpg");
$images[2] = ("3.jpg","1.jpg","2.jpg");

I want to change the position every refresh of my image like $images(array) above
My code like this :

<?php
$a=1;
$i=3;
while($a<=$i){
$images[$a] = ("$appear");}
//$appear is list of image above but I create it with random()
?>

I have 2 question for this problem :

  1. I want to get value where $a=1 and $a=2 images appear as
    $images[1] = ("2.jpg","3.jpg","1.jpg");and
    $images[2] = ("3.jpg","1.jpg","2.jpg");
    Could I get that value?
    which code would I use?
  2. I want to use javascript for recall $a=1;
    if $a had finished (for loop again)....
    Could you help me?

I am sorry if My Attitude and My Language is fall apart I hope you can understand My Idea Thank you for you greatful ^^

Was it helpful?

Solution

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..?

OTHER TIPS

I think you just have some syntax issues.

Arrays in PHP are in this form: $images = array('1.jpg', '2.jpg', '3.jpg');

if you want a random image use: $image = array_rand($images);

Cheers!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top