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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:30:22+00:00 2026-06-01T21:30:22+00:00

I have a slight problem. I have several arrays in php with different team

  • 0

I have a slight problem. I have several arrays in php with different team names. Each array contains teams of a certain league. When I click an add button I get the option to add a new entry to the calendar. I want the drop down to have only the teams for that league. onclick of the add button I call a javascript function that knows what division was clicked. However in order to give the javascript the information for which teams to display I have to pass it one of the php arrays. The problem I am having is telling php which array to pass to javascript depending on which league javascript is on. I don’t want to specify the array myself because there is an option to add a league and this would mean having to code in more code each time a league is added. The point of the site is being dynamic.

here is some code.

for ($i = 0;$i<$sizeof($leaguesarray);$i++){
    $htmlimploded[$i] = implode($html[$i]);
}

here I have used emplode to make all of my php arrays readable into javascript.

for (var h = 0; h<size; h++){ // goes through every league 
    if(h == leaguenum){ // finds the league for the clicked add button
        // this is the line that I have trouble with I can't think of 
        //anyway of telling it which array to use since it is serverside code.
        var myarray = ["<? echo $htmlimploded[]?>"]; 
    }
}

Javascript code above.

  • 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-01T21:30:24+00:00Added an answer on June 1, 2026 at 9:30 pm

    Imploding works but why not json_encode($array)? It’s a simpler, built in way to turn php arrays into javascript objects or arrays. If you have something like:

    $league1 = array('team1', 'team2');
    $league2 = array('team3, 'team4') ;
    

    Then make a multidimensional associative array of these:

    $all_teams = array('league1'=>$league1, 'league2'=>$league2);
    

    encode it into a Javascript object and print it into your JS:

    $encoded = json_encode($all_teams);
    print 'var teamObject = '.$encoded.';';
    

    If you were to console.log(teamObject) you’d see something like this:

    {"league1": ["team1", "team2"], "league2": ["team3", "team4"]}
    

    Looks complicated, but now you can pull out the array you desire very easily. The league 1 array is teamObject.league1 and the league2 array is teamObject.league2, and so on.

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

Sidebar

Related Questions

I have a slight problem, I have a date format coming from php my
people. I have slight problem with GD2 text on image. I have everything working
I have a slight problem with a path: D:\\Music\\DJ Ti%C3%ABsto\\Tiesto\\Adagio For Strings (Spirit of
I have a slight problem... we made a change to our url structure the
I have a slight problem, I am trying to capture the input of two
am new here. i have a slight problem; PLease look at the following code
I've wrote this simple piece of code. And I have a slight problem with
hey everyone, here is the site SEE BELOW I have a slight jquery problem
I have a slight problem and cannot for the life of me figure out
I have a slight problem with .htaccess redirect. I have a dynamic site with

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.