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 6029047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:49:44+00:00 2026-05-23T04:49:44+00:00

I am trying to use PHP associative arrays to echo different values for text

  • 0

I am trying to use PHP associative arrays to echo different values for text and images into HTML for different instances of a jQuery slideshow on the same page. Here’s the HTML:

<div class='slide'>
    <div class='mosaic-block fade'>
        <div class='mosaic-overlay'>
        <div class='text'><p>This is the text!</p></div>
            </div>
        <div class='mosaic-image'><img src='imgs/the-img.png'/></div>
    </div> <!-- mosaic-block fade -->
</div> <!-- .slide --> ` 

I wrote arrays for each type of slideshow containing the text and image for each slide, here’s and example:

$my_content = array( 
        'image1.png' => 'image1 text!',
        'image2.png' => 'image2 text!'
        );

Then I wrote a function with parameters for the category of slideshow and the content:

function gallery_content($content) {
    foreach ( $content as $img => $txt ) {
    echo "<div class='slide'>
        <div class='mosaic-block fade'>
        <div class='mosaic-overlay'>
            <div class='text'><p>".$txt."</p></div></div>
            <div class='mosaic-image'><img src='imgs/other/".$img."'/></div>
        </div> <!-- mosaic-block fade -->
        </div> <!-- .slide --> ";
}

I call it like this: gallery_content($my_content); and it works really well. But when I try to call it again for another set of values, only the first instance seems to work. I tried using the array directly instead of the variable as a parameter AND making a separate function for each slideshow, but keep getting the same results.

Why can’t the function be called more than once? Thanks in advance.

  • 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-05-23T04:49:44+00:00Added an answer on May 23, 2026 at 4:49 am

    See the source code that is generated on your final page(HTML) to judge whether PHP did its work or not. i think thats your resultant “galaries”(DIV) might be having the same ID or other attributes thorugh which the jQuery activates them, and so only one is being run properly (the first one), and the second one is not run.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use PHP to return SQL values into an HTML table.
I am going nuts trying to use PHP to get and insert values into
I am trying to use PHP to send text to an LED sign so
I'm trying to use PHP to store username and password to a text file
I am trying to use jQuery with PHP, like this: <th bgcolor=#FFCC00 align=center> <a
I'm trying to use PHP's split() (preg_split() is also an option if your answer
I am trying to use PHP and cURL to log in to a website
i am trying to use php-openid library for implementing openID in my site. the
I am trying to use PHP session without using cookies. I have enabled session.use_trans_sid
I am using a multidimensional array and I am trying to use php to

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.