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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:18:16+00:00 2026-06-18T04:18:16+00:00

I have this PHP file wherein I need this javascript variable available (inside the

  • 0

I have this PHP file wherein I need this javascript variable available (inside the same file) to be pass on my PHP variable, something like this.

myfile.php contais:

    var testing  = ["EWMLMc3ES3I", "RSdKmX2BH7o", "SIXwlxhjaKY", "acp8TbBPVos", "6GpKR4-TLoI", "XLKLkTnKRwg", "6WPELkw5kD0"];

and I want to make it like this

 testing = <?php $new_testing ?>

I need a suggestion maybe a jquery snippet but with something like my scenario which is a javascript in a php file.


edit: additional info, the reason for this is , because there’s another javascript codes (not on the same file but rather had it include via external JS) that needs that particular PHP variable.
so say here’s the logic:

  1. javascript_variable —> php_variable (passing the javascript variable to php) then,
  2. php_variable –> another_javascript_variable (pass the php to another javascript file)
  3. the another_javascript_variable will the be executed by that external javascript file
  • 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-18T04:18:17+00:00Added an answer on June 18, 2026 at 4:18 am

    On your PHP side, use json_encode() to convert your php array to a suitable format to pass it to the javascript.

    PHP:

    $var = array( 'lorem', 'ipsum', 'dolor');
    $json_var = json_encode($var);
    $parameter = array( 'js_var' => $json_var );
    wp_enqueue_script('my_script');
    wp_localize_script('my_script', 'object_name', $parameter); 
    

    Javscript:

    <script>
    my_var = jQuery.parseJSON(object_name.js_var);
    alert(my_var); 
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP File with something like this: <script type=text/javascript> var page =
I have this code which will include template.php file from inside each of these
I have this Javascript function that sends username and password to php file through
I have a php file that looks like this: <?php include(config.php); // put the
I have one line in php file like this: <a class=hide-if-no-js onclick=findPosts.open( 'media[]','<?php echo
So, i have this form in a php file and i want it to
I have this code in PHP writing views to a text-file and just increasing
I have the following code: if (include_once(dirname(__FILE__).'/file.php') || include_once(dirname(__FILE__).'/local/file.php') ) { This causes an
I'm new to web development.I have a php file such as addcourse.php.In this file
I have a php file which has a require_once Statement (?) this file is

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.