Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8679185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:54:28+00:00 2026-06-12T20:54:28+00:00

<?php // Random Image With Link // https://getbutterfly.com/ // // Usage: // // Save

  • 0
<?php
// Random Image With Link
// https://getbutterfly.com/
//
// Usage:
//
// Save this file as ads.php and use the include function to call it inside your web site

function display_random_img($array) {
    $key = rand(0 , count($array) -1);
    $link_url = $array[$key]['url'];
    $alt_tag = $array[$key]['alt'];
    $random_img_url = $array[$key]['img_url'];
    list($img_width, $img_height) = getimagesize($random_img_url);
    return "<a href=\"$link_url\"><img src=\"$random_img_url\" width=\"$img_width\" height=\"$img_height\" alt=\"$alt_tag\" /></a>";
}

// Edit the following values accordingly
$ads_array = array(
    array(
        'url' => 'http://www.google.com/',
        'alt' => 'Google',
        'img_url' => 'images/1.png'
    ),
    array(
        'url' => 'http://www.yahoo.com/',
        'alt' => 'Yahoo!',
        'img_url' => 'images/2.png'
    ),
    array(
        'url' => 'http://www.msn.com/',
        'alt' => 'MSN',
        'img_url' => 'images/3.png'
    )
);
$ads_array_1 = array( // add or remove accordingly
    array(
        'url' => 'http://www.google.com/',
        'alt' => 'Google',
        'img_url' => 'images/1.png'
    ),
    array(
        'url' => 'http://www.yahoo.com/',
        'alt' => 'Yahoo!',
        'img_url' => 'images/2.png'
    ),
    array(
        'url' => 'http://www.msn.com/',
        'alt' => 'MSN',
        'img_url' => 'images/3.png'
    )
);

echo display_random_img($ads_array);
echo display_random_img($ads_array_1); // add or remove accordingly
?>

While searching on the internet for a viable PHP array randomizer function, this is what I ended up with. It works perfectly, there are url, alt, img_url.
I don’t know how to show text over/with the image?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:54:29+00:00Added an answer on June 12, 2026 at 8:54 pm

    Simple:

    1) Add title to the array :

    array(
        'url' => 'http://www.google.com/',
        'alt' => 'Google',
        'img_url' => 'images/1.png',
        'title' => 'Google Title'
    ),
    

    2) Replace your function with

    function display_random_img($array) {
        $key = rand(0 , count($array) -1);
        $link_url = $array[$key]['url'];
        $alt_tag = $array[$key]['alt'];
        $random_img_url = $array[$key]['img_url'];
        $title = $array[$key]['title'];
        list($img_width, $img_height) = getimagesize($random_img_url);
        return "<a href=\"$link_url\"><img src=\"$random_img_url\" width=\"$img_width\" height=\"$img_height\" alt=\"$alt_tag\" title=\"$title\" /></a>";
    }
    

    If You want Your title to be next to the image or whatever, just make the relevant corrections in html :

    return "$title : <a href=\"$link_url\"><img src=\"$random_img_url\" width=\"$img_width\" height=\"$img_height\" alt=\"$alt_tag\" title=\"$title\" /></a>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this random page script which is in PHP file. I'm a bit
Like a random image generator (ex: http://www.dustindiaz.com/a-simple-php-image-rotator/ ), only in a sequential order. Im
The following link outputs a different image every time you visit it: http://www.biglickmedia.com/art/random/index.php From
I am using the following php script to show a random image on my
i have a php function which returns a random json encoded color <?php function
I actually want to generate random password using PHP uniqid() function $randomPassword = uniqid();
I want to use the function gmp_random() by GNU MP in PHP. I need
Is there any php function in our time, which generates absolutely unique, random string?
Having some issues, basically I have a random image gallery. This is the code
I'm using this php code for an image upload. But I keep getting an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.