Can't call PHP functions from JavaScript?

Therefore you can’t call PHP functions directly from JavaScript code. However, what you can do is post an AJAX request (it calls a PHP file behind the scenes) and use that to run your PHP code and return any data you require back to the JavaScript. Basically, you are mixing server-side (PHP) and client-side (JS) scripting.
For More Information Please Refer:

You May Also Like to Read: