0

php

<?php $name = 'David'; function getName() { global $name; echo $name; } getName(); ?> // why would you use so many commands to generate one name

11th Apr 2018, 3:49 AM
sean
2 odpowiedzi
+ 3
You could just use echo ‘David’; inside the php tags to get the same results
11th Apr 2018, 4:17 AM
Ariela
Ariela - avatar
+ 2
if you don't use function insside php then you can print using echo "David", but here you have used function() so inside function you need global to get $name from outside the function then print echo $name and getName(); runs the function outside the function
11th Apr 2018, 4:23 AM
Sudarshan Rai
Sudarshan Rai - avatar