I tried ro do math with function in php | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I tried ro do math with function in php

<?php $a = 1 $b = 1 function sayHello() { echo $a / $b; } sayHello(); //call the function ?> Help, please

9th Jul 2017, 3:11 AM
rustic crow
2 Answers
+ 2
the first answer is right, your function don't have access to the "$a" and "$b" variables, you should pass them as parameters function sayHello($a,$b){ echo $a/$b; } sayHello(1,1);
9th Jul 2017, 4:20 AM
luis sanchez
luis sanchez - avatar
+ 7
your indentation for the calling of the function? That seems wrong...
10th Jul 2017, 11:34 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar