php $var store Mathematical expression [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
$VAR= 5;
$VAR1=30;
Mathematical expression :- 5 * 60 * 60 + 30 * 60
i.e. 5 and 30 are $VAR and $VAR1 respectively.
how to use this manually in php code and store result in $RESULT.

This will work:
$result = $VAR * 60 *60 +$VAR1 *60;
The following link will give you an idea of order of preferance

Here is your expression
<?php
$VAR = 5;
$VAR1 = 30;
$calc = - $VAR * 60 * 60 + $VAR1 * 60;
echo $calc;
?>

Related

idk what this php code does can someone tell me? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 days ago.
Improve this question
<?php
$seed = 'COPY_RAFFLE_SEED_HERE'; // Randomly generated seed [Seed:]
$raffle_id = 'COPY_RAFFLE_ID_HERE'; // Raffle ID [Raffle ID:]
$entries = 10; // Number of tickets [Entries count:]
/*
*
* Must +1 return value since it starts with 0
* 28 characters offset to get 4 characters from both hashes
*
*/
$randomNumber = (hexdec(substr(md5($seed) . md5($raffle_id), 28, 8)) % $entries)+1; // Must use +1 as it starts with 0
echo "Ticket with number #$randomNumber won";
apparently this is the code used for the giveaways, and i wanted to see how it works

Convert H:i:s hour style in other format [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to know how can I change
$var = "01:30:00";
to
$var = "1.5";
in PHP ?
Thanks.
Something along these lines...
<?php
function timeToHours($time) {
$hoursMinsSecs = explode(':', $time);
return $hoursMinsSecs[0] + $hoursMinsSecs[1] / 60 + $hoursMinsSecs[2] / 3600;
}
$var = "01:30:00";
echo timeToHours($var);
?>

PHP percent calculation not working [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have this a record of: 10/2 * 100%
This is equal to 5
How does it save in PHP?
This not work:
($int1/$int2) * 100
Assuming $int1 = 10 and $int2 = 2, you'd have this sum;
echo (10 / 2) * 1; //1 being 100%
Which outputs 5.
http://codepad.org/twp2TduF
There is nothing wrong - it gives your desired result. I assume you were * 100, which would give 500.
Other percentages
* 0.25 = 25%
* 0.75 = 75%
..and so-on
Or refer to this answer
You cannot use percentage this way.
You will need to divide them by 100:
<?php
$int1 = 3;
$int2 = 6;
echo ($int1/$int2) * 100/100;
this above is 100%
and this:
echo ($int1/$int2) * 25/100;
is 25%

php round up decimals not working [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a bit of code but it is not echoing the correct answer, or in the correct format. I tried the round function but that didnt show anything
here is my code
$total_per_year = 308790;
$fat = $total_per_year / 3500;
echo $fat;
it is currently showing it as 0.088, but the correct answer is 88.2257142857
how can i do this so it round up to 88.2
The round function requires two parameters like so:
echo round($fat,1);
The second parameter being the amount of decimal places you require.
I have had issues previously with round not working as expected and I had to use number_format:
echo number_format((float)$fat,1,'.','');
With 1 being the decimal places required, the full stop being the decimal separator and '', being the thousand separator.
Use round()
echo round($fat, 1); //second argument is precision eg. decimals
See this for documentation: http://dk1.php.net/round
right, i worked this out now. I know i kept getting '0.088'. And this is wrong.
Its because i had it like this
$total_per_day = number_format($total_per_cup * $number_of_cups);
$total_per_year = number_format($total_per_day * 365);
$fat = round($total_per_year / 3500, 1);
echo $fat;
echo $total_per_year;
this is the correct code.
$total_per_cup = $type_calorie + $milk_calorie + $sugar_calorie;
$total_per_day = $total_per_cup * $number_of_cups;
$total_per_year = $total_per_day * 365;
$fat = $total_per_year / 3500;
echo json_encode(array('total'=> number_format($total_per_year) , 'perday' => number_format($total_per_day), 'fat'=> round($fat, 1)));

Get value from a percentage from a range of 2 numbers [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
For example I have this range:
20 to 200
How can I programmatically get the value for a specific percentage, lets say 40% between those 2 numbers?
Simple example:
0 to 200
I want to get the value of 40%. Answer is 80.
Try this:
function percentage_from_range($from, $to, $percentage) {
$result = (($to - $from) / 100 * $percentage) + $from;
return $result;
}
e.g.
echo percentage_from_range(20, 200, 40); //92
$num1=20;
$num2=200;
$percent=40;
$total=$num2-$num1;
$result = (($total/100) * $percent)+$num1;
$lwb = 20;
$upb = 200;
$perc = 40;
$value = $lwb + ($upb - $lwb) * $perc / 100;
Takes perc/100 part of range, and start with the lowerbound.

Categories