amg182 Posted June 26, 2011 Share Posted June 26, 2011 Hi just a quick question. How can i assign a calculation/formula as a variable? I would like something like this(if possible): <?php......... $distance='.round($hypot/1000,2).'; ?> ... <?php echo $distance; ?> Thanks Link to comment https://forums.phpfreaks.com/topic/240450-assigning-varibales/ Share on other sites More sharing options...
EdwinPaul Posted June 26, 2011 Share Posted June 26, 2011 Indeed, it's that simple: <?php $a = ($b / $c) * 1,5 + $d; // or whatever formula you desire... echo $a; ?> Link to comment https://forums.phpfreaks.com/topic/240450-assigning-varibales/#findComment-1235043 Share on other sites More sharing options...
cs.punk Posted June 26, 2011 Share Posted June 26, 2011 <?php $distance = round($hypot/1000, 2); echo $distance; ?> Link to comment https://forums.phpfreaks.com/topic/240450-assigning-varibales/#findComment-1235044 Share on other sites More sharing options...
amg182 Posted June 26, 2011 Author Share Posted June 26, 2011 Thanks! Really appreciate your help! Link to comment https://forums.phpfreaks.com/topic/240450-assigning-varibales/#findComment-1235059 Share on other sites More sharing options...
Andy-H Posted June 26, 2011 Share Posted June 26, 2011 Do you mean the actual formula as opposed to the result? Look into anonymous functions. $distance = function($hypot) { return round($hypot/1000, 2); }; $hypot = 25000; echo $distance($hypot); Link to comment https://forums.phpfreaks.com/topic/240450-assigning-varibales/#findComment-1235063 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.