0

what is the expected output should we add any parameters to get output

<?php function add_numbers($a = 5, $b){ return $a + $b; } ?>

21st Sep 2017, 7:33 AM
Srikanth iyer
Srikanth iyer - avatar
2 ответов
+ 2
Well, there's no output, your code didn't have any instructions for printing any output. Do you need to add any parameters? I think not, your function already had its parameters declared, what is left for you to do would be to test that code, probably add a line like: echo add_numbers(40,2); NOTE: An optional parameter must be followed by another optional parameters, in your function the first parameter is optional, so the second parameter should be made optional also, or, put mandatory parameters first, then followed by optional parameters. Hth, cmiiw
21st Sep 2017, 8:36 AM
Ipang
+ 1
you have wrong in your code change it like this <?php function add_numbers($a, $b=5){ echo $a + $b; } add_numbers(4); //or add_numbers(4,8); ?> you can not use default parameter value in left side u can only use in right side of parameters
21st Sep 2017, 8:47 AM
Akbar Khalilzadeh
Akbar Khalilzadeh - avatar