0

I need call javascript variable in php. You can see this code :

<?php 

        for($x=0; $x < count($payload); $x++){ 
          $datanya = $payload[$x];
        ?>

        <script type="text/javascript">
        var mean = "<?php echo $mean; ?>";           
        var stdev = "<?php echo $standartdeviation; ?>";  
        var datanya = "<?php echo $datanya; ?>"; 
                
        var lognormdist = formulajs.LOGNORMDIST(datanya, mean, stdev, true);          

        </script>

        <?php 
        }
        ; 
// I wanna call variable javascript (lognormdist) here, as $lognormdist
?>

If need, $payload is array of my data = [52.89, 68.03, 71.19, 86.02, 89.15, 89.84, 89.85, 103.37 111.17, 115.07, 115.18, 116.32, 123.72, 132.14, 181.27]

Function formulajs.LOGNORMDIST is from formulajs.info/functions

or Anybody can help me with PHP Code of LOGNORMDIST, and also I need LOGPEARSONDIST in PHP Code :)

Gino
  • 13
  • 3
  • You can't. JS is client-side, PHP is server-side. To do what you're going for, you would need an AJAX call. – El_Vanja Dec 18 '20 at 15:38
  • ohh sorry, I can't doing that. I didnt know how can I use AJAX on this problem. Do you can help me for the code? – Gino Dec 18 '20 at 15:45
  • 1
    It's a broad subject and I don't know anything else about your application, so it'd be difficult to say what the right approach is. You can check out MDN's [AJAX tutorial for beginners](https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started). – El_Vanja Dec 18 '20 at 15:48
  • 1
    @El_Vanja - can you throw that into an answer so we can get an accepted answer on the question now that he knows his next step? I can see him not being the last person confused by that. – Alex H. Dec 18 '20 at 16:35
  • Does this answer your question? [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – El_Vanja Dec 18 '20 at 16:41
  • @AlexH. Questions about this basic misconception are asked daily. The correct procedure is identifying a duplicate that would get the OP on the right path (your comment actually reminded me that I forgot that part). Answering this is hardly going to set any future readers on the right path, as the question is formed around some specific statistical functions. – El_Vanja Dec 18 '20 at 16:43
  • Ouhh, sorry if I'm troublesome. But, i still learning, is about 1 month maybe. If anybody know, please give me some code for Lognormdist Function & Logpearsondist Function? :) – Gino Dec 19 '20 at 13:25

0 Answers0