
This post was last updated on January 1st, 2025 at 06:39 am
Hi Dev,
Today, i we will show you PHP variables pass in javascript example. This article will give you simple example of PHP variables pass in javascript example. you will PHP variables pass in javascript example. In this article, we will implement a PHP variables pass in javascript example.
So let’s follow few step to create example of PHP variables pass in javascript example.
Example 1
<?php $message = "Hello World!"; ?> <!DOCTYPE html> <html> <head> <title>PHP Variables Pass In JavaScript Example</title> </head> <body> <h1>PHP Variables Pass In JavaScript Example</h1> <script type="text/javascript"> var message = "<?php echo"$message"?>"; alert(message); </script> </body> </html>
Example 2
<?php $fruits = ['orange' => 'mango', 'yellow' => 'banana', 'red' => 'apple']; $json_fruits = json_encode($fruits); ?> <!DOCTYPE html> <html> <head> <title>PHP Variables Pass In JavaScript Example</title> </head> <body> <h1>PHP Variables Pass In JavaScript Example</h1> <script type="text/javascript"> var fruits = <?php echo($json_fruits)?>; alert(fruits.yellow); </script> </body> </html>
I hope it will assist you…