Languages :: PHP :: make a function to read the value from another function |
|||
| By: rac2000 |
Date: 05/10/2003 00:00:00 |
Points: 50 | Status: Answered Quality : Excellent |
|
i need to make a function to read the result from another function. what i did is an example with the calculation of a+b. what i whant to do is to be able to echo the value of a+b with the function main. where is the mistake? function main() { a=5 b=10 calcul (a,b) return val } function calcul(a.b) { a+b return val } |
|||
| By: rac2000 | Date: 05/10/2003 16:24:00 | Type : Comment |
|
| Can I make a class of functions ant to link them somehow? |
|||
| By: VGR | Date: 06/10/2003 05:02:00 | Type : Comment |
|
| c'ets simple : il manque les instructions genre print ou echo ;-)) function main() { $a=5 $b=10 $val=calcul ($a,$b); return $val; } function calcul($a.$b) { $res=$a+$b; return ($res); } |
|||
| By: VGR | Date: 06/10/2003 05:03:00 | Type : Answer |
|
| to print : echo "le résultat est $val "; dans main.php après l'affectation de $val=calcul($a,$b); |
|||
| By: rac2000 | Date: 06/10/2003 05:42:00 | Type : Comment |
|
| as you can see i had the concept write. maybe i made some mistakes in the variables names. i have no ideea why it wasn't working. you had a litle mistake in your code to. in the calcul you put a dot insted of comma . here is the working code : <? function main($a,$b) { $val=calcul($a,$b); return $val; } function calcul($a,$b) { $res=$a+$b; return $res; } $x=main(5,5); echo "le résultat est $x "; ?> thanks. |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








