shows the use of the modular function %
example of returning more than one value from a function
see it working at http://sarahk.pcpropertymanager.com/muck/divide2.php
get2vals returns integers of the number divided by 2
<?php
function get2vals ( $num )
{
$valone = intval ( $num / 2 );
$valtwo = $valone ;
if (( $num % 2 ) > 0 ) $valtwo ++;
return array( $valone , $valtwo );
}
if ( $_GET [ 'num' ]) {
list( $answer1 , $answer2 ) = get2vals ( $_GET [ 'num' ]);
echo "<table border='0' cellpadding='4'>
<tr><td> </td><td align='right'> { $answer1 } </td></tr>
<tr><td align='right'>+</td><td align='right'> { $answer2 } </td></tr>
<tr><td>Total</td><td align='right'> { $_GET [ 'num' ]} </td></tr>
</table>" ;
}
?>
<form action='divide2.php' method='get'>
Number: <input type='text' size='3' name='num' maxlength='6' onchange='javascript:submit()' >
<input type='submit' value='Divide by 2!' >
</form>
abs -- Absolute value Categories : PHP , PHP Functions , Math. Arbitrary Precision Math using BCMATH routines Categories : PHP , Math. , BC math Diffusion-Limited Aggregation visualization Categories : PHP , Graphics , Algorithms , Math. Show the steps for converting a number from a given base to base 10. Shows the steps involved in converting a number from a given base to base 10. Categories : PHP , Math. , Algorithms Calculator for Baroque Violin strings Categories : Math. , PHP , Strings Prime number finder (Sieve of Erastothenes) Categories : PHP , Algorithms , Math. Greatest Common Denominator - A simple class that finds the greatest common denominator for two integers.
Categories : PHP , PHP Classes , Math. Reverse a given number Categories : PHP , Beginner Guides , Algorithms , Math. Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP , PHP , HTML , PDF , Excel Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other? Categories : PHP , Math. , Arrays Temperature Conversion Categories : PHP , Math. , Beginner Guides grab the result of any calculation you submit to the Google Calculator. Categories : PHP , Arrays , Web Services , Regexps , Math. 3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations. Categories : Graphics , Math. , PHP Classes , PHP , Charts and Graphs Math operations on big numbers Categories : PHP , Math. Latitude-Longitude to Miles Categories : PHP , Utilities , Math.
matthew waygood wrote : 1145
why dont you just:-
function get2vals($num)
{
$valone = floor($num / 2);
$valtwo = ceil($num / 2);
return array($valone, $valtwo);
}