No problem, my love. I'll assume you know absoultely nothing, just for fun.
Ok - well to add two strings together you use a dot, full-stop whatever you call it in your chunk of mud, so
echo 'one' . 'two' . 'three'
would output onetwothree. It also works with variables, so if $num was defined to 88,
echo $num . ' is a number';
would output 88 is a number.
Functions can return values - strings, integers, objects, resources - pretty much anything, in the function below I'm returning a string that. You can use echo followed by a function to echo what it returns, hence the echo what_range(24) at the end. Functions can also take arguments in the bracketty bit after the function name, and you refer to them in the function by whatever name you put in
function wahhh($name)
{
echo 'Hello ' . $name;
}
That function doesn't return anything, but does the printing itself instead.
do / while loops - they do whatever's between the braces { and } while the condition at the end is true - in the case of what_range until $range gets bigger than $limit - so stops when $range goes over 100 in the example
<?php
function what_range($num)
{
// return a string saying the value is sub-zero
if ($num < 0) return $num . ' is Less than zero';
// return a string saying the value is zero (putting $num is pointless here but nevermind)
if ($num == 0 ) return $num . ' is zero';
$limit = 100; // when to stop
$range = 10; // what to start at
$interval = 10; // how big the gaps are between steps
do // start the loop
{
// if the number is less than or equal to $range return the value of $range, and its lower limit
// which is ($range - $interval + 1) eg, if $range at this point is 60, our interval is 15 it would
// return 56 is between 46 and 60 (range changes every execution of the loop) echo it if you like
echo 'checking between ', ($range-$interval+1), ' and ', $range, '<br />';
if ($num <= $range)
return $num . ' is between ' . ($range-$interval+1) . ' and ' . $range;
$range += $interval; // the valud of $interval is added to $range
}
while ($range <= $limit); // stop if $range is beyond the rim
// being here means the function didn't return already, so the value is GREATER than our limit, so tell them that
return $num . ' is greater than ' . $limit;
}
echo what_range(24);
?>
Ok, that's enough of that.