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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:07:53+00:00 2026-05-31T19:07:53+00:00

I had a weird problem here. Please check the code below. I do not

  • 0

I had a weird problem here. Please check the code below. I do not understand how this code below is created by somehow part of it is working, considering mixture of php variables and javascript variables.

First, let us see what the alert() outputs (take note that $lat and $lng is different from the array $vlat):

  1. In Line 8 of the code below, alert(eventlocation) properly displays the coordinates of the GoogleMap latlng (so the implementation is correct)

  2. In Line 13, alert(s) was able to display incrementing values (i.e. 0,1,2,3,4,..) based on the for loop in the previous line so it is also correct.

  3. In Line 14, alert($vlat[0]) was able to display the latitude of the first element of that array (declared before this set of codes) so it is also correct

  4. In Line 15, alert($vlat[1]) was able to display the latitude of the second element of that array so it is also correct

  5. But in Line 16, alert($vlat[s]) displayed undefined.

Can anyone explain that? Thanks

    echo "<script src= 'http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA2jrOUq9ti9oUIF0sJ8it1RTNr3PHi_gURF0qglVLyOcNVSrAsRRu2C3WQApcfD0eh9NLdzf9My0b9w' type='text/javascript'> </script>
    <script language='javascript' type='text/javascript'>
    function getabc(){
        var eventlocation;
        var volunteerlocation;
        var s;
        eventlocation = new GLatLng($lat, $lng);
        //alert(eventlocation);
        var volunteerDist = new Array();
        s = $ctr;
        var tvid = new Array();
        for(s=0;s<$numrows;s++){
            //alert(s);
            //alert($vlat[0]);
            //alert($vlat[1]);
            //alert($vlat[s]);
        }
    }
    a = getabc();     < /script>";
  • 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-31T19:07:54+00:00Added an answer on May 31, 2026 at 7:07 pm
    alert($vlat[0]);
    alert($vlat[1]);
    alert($vlat[s]);
    

    $vlat[0], $vlat[1] and $vlat[s] are parsed on the server before they is sent to the client. The first two can be resolved, but PHP does not know what s is, since s is only defined once the client side is reached.

    Edit from chat discussion

    $json = json_encode($vlat);
    
    echo "<script language='javascript' type='text/javascript'>
       function test(){
           var obj = JSON.parse('$json');
           alert(obj);
       }
       < /script>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a weird problem, where I opened up a source code project for
Got a weird problem here. I have created a template for a ListBox based
As you can tell by the script below, I have a problem, I'm not
I have this weird problem where my Google Maps API script doesn't work, no
This is a really weird problem. It's taken me practically all day to whittle
EDIT: This is not a problem with the jQuery creating the appropriate markup from
Some weird problem is haunting me right now: One of my apps (not yet
I've been working on a Java project for year. My code had been working
I had a weird idea about a hashing function. The problem statement is You
I have a really weird WCF problem here... We're connecting to a crappy third-party

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.