John Davidson

I need convert or get javascript variable in php variable - lognormdist logpearsondist

0 comments
Message:


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 :)



My Answer:
To get the `lognormdist` variable from JavaScript to PHP, you can use AJAX to send the variable to a PHP script and then retrieve it in PHP. Here's an example of how you can do this:

1. Modify your JavaScript code to send the `lognormdist` variable to a PHP script using AJAX:

javascript
var mean = "";
var stdev = "";
var datanya = "";

var lognormdist = formulajs.LOGNORMDIST(datanya, mean, stdev, true);

// Send lognormdist variable to PHP script using AJAX
$.ajax({
type: "POST",
url: "get_lognormdist.php",
data: { lognormdist: lognormdist },
success: function(response) {
console.log("Lognormdist sent to PHP script");
}
});


2. Create a PHP script (get_lognormdist.php) to receive the `lognormdist` variable and store it in a PHP variable:

php
if(isset($_POST['lognormdist'])) {
$lognormdist = $_POST['lognormdist'];
// You can now use $lognormdist in your PHP code
echo $lognormdist;
}
?>


Now, the `lognormdist` variable will be sent from JavaScript to the PHP script using AJAX, and you can retrieve it in the PHP script and store it in a PHP variable for further processing.

For the `LOGPEARSONDIST` function in PHP, you can use the `stats_distributions` extension in PHP. Here's an example of how you can calculate the `LOGPEARSONDIST` in PHP:

php
// Calculate LOGPEARSONDIST in PHP
function logpearsondist($x, $mean, $stdev) {
$z = log($x) - $mean;
$logpearsondist = 1 / (sqrt(2 * M_PI) * $stdev * $x) * exp(-($z * $z) / (2 * $stdev * $stdev));
return $logpearsondist;
}

// Usage
$mean = 10; // Mean value
$stdev = 2; // Standard deviation
$x = 5; // Input value
$logpearsondist = logpearsondist($x, $mean, $stdev);
echo $logpearsondist;
?>


You can use the `logpearsondist` function in your PHP code to calculate the `LOGPEARSONDIST` for your data.

Rate this post

3 of 5 based on 4385 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us