Jump to content

[SOLVED] maths function. need little advice


redarrow

Recommended Posts

advance thank you.

 

can anybody think off a beeter way as a function,

to add numbers and times numbers and minus numbers,

within a function.

 

it for a shopping cart but i wanted a neater way.

 

my example.

<?php

function maths($val1,$val2){

$add=$val1+$val2;
$take_away-$val1-$val2;
$times=$val1*$val2;

$maths_array['add']=array($add);
$maths_array['away']=array($take_away);
$maths_array['times']=array($times);

return $maths_array;
}

$maths_array=maths(10,5);

echo $maths_array['add'][0];

echo $maths_array['away'][0];

echo $maths_array['times'][0];

?>

SOLVED.

 

That it, now i got start and end number.

<?php

function maths($val1,$val2){

$add=$val1+$val2;
$take_away-$val1-$val2;
$times=$val1*$val2;

$maths_array['add']=array($add);
$maths_array['away']=array($take_away);
$maths_array['times']=array($times);

return $maths_array;
}

$start_number=10;

$end_number=5;

$maths_array=maths($start_number,$end_number);

echo $maths_array['add'][0];

echo $maths_array['away'][0];

echo $maths_array['times'][0];

?>

thank you.

 

A am finally using arrays and functions for my projects and it well good fun.

thanks for your help.

 

once i fully understand functions and arrays within functions then the dreaded class lol.

 

even better.

<?php

function maths($val1,$val2){

$add=$val1+$val2;
$take_away-$val1-$val2;
$times=$val1*$val2;

$maths_array['add']=$add;
$maths_array['away']=$take_away;
$maths_array['times']=$times;

return $maths_array;
}

$start_number=10;

$end_number=5;

$maths_array=maths($start_number,$end_number);

echo $maths_array['add'];

echo $maths_array['away'];

echo $maths_array['times'];

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.