Here we will show how you can pass PHP variables to JavaScript and use it into JavaScript function. To do that, you can simply use echo()
function into JavaScript variable value.
PHP is server side language which retrieves server and show in client side. JavaScript is client side language which manipulate HTML and data receives from server. So we need to pass PHP data into JavaScript variables and function.
inflay.com | Pass PHP variable to JavaScript
Pass PHP variable to JavaScript
PHP data is an array or a object than we need to convert it to Json object format using json_encode()
function.
"35", "Ben"=>"37", "Joe"=>"43");
$json_age = json_encode($age);
?>
inflay.com | Pass PHP variable to JavaScript
Pass PHP variable to JavaScript
I hope this article helps you.
Thanks for visiting Inflay.com .