How To Use PHP Variables To JavaScript Example
Hello,
Right now, i we are going to present you how you can use PHP variables to javaScript instance. This text gives you easy instance of how you can use PHP variables to javaScript instance. you’ll learn to use PHP variables to javaScript instance. So let’s comply with few step to create instance of how you can use PHP variables to javaScript instance.
Instance: 1
<?php $message = "Whats up World!"; ?> <!DOCTYPE html> <html> <head> <title>How To Use PHP Variables To JavaScript Instance</title> </head> <physique> <h1>How To Use PHP Variables To JavaScript Instance</h1> <script kind="textual content/javascript"> var message = "<?php echo"$message"?>"; alert(message); </script> </physique> </html>
Instance: 2
<?php $fruits = ['orange' => 'mango', 'yellow' => 'banana', 'red' => 'apple']; $json_fruits = json_encode($fruits); ?> <!DOCTYPE html> <html> <head> <title>How To Use PHP Variables To JavaScript Instance</title> </head> <physique> <h1>How To Use PHP Variables To JavaScript Instance</h1> <script kind="textual content/javascript"> var fruits = <?php echo($json_fruits)?>; alert(fruits.yellow); </script> </physique> </html>
I hope it’ll help you…
Komentar
Posting Komentar