Debug School

rakesh kumar
rakesh kumar

Posted on

Php Programming Question

solution:click here for soution

1.Find a output of following program

<?php  
     $fname = "Gunjan";  
     $lname = "Garg";  
     echo "My name is: ".$fname,$lname;  
?>  

Enter fullscreen mode Exit fullscreen mode

2.

<?php  
     $fname = "Gunjan";  
     $lname = "Garg";  
     print "My name is: ".$fname,$lname;  
?>  

Enter fullscreen mode Exit fullscreen mode

3.

<?php  
     $lang = "PHP";  
     $ret = echo $lang." is a web development language.";  
     echo "</br>";  
     echo "Value return by print statement: ".$ret;   
?>  


Enter fullscreen mode Exit fullscreen mode

4.

<?php  
     $lang = "PHP";  
     $ret = print $lang." is a web development language.";  
     print "</br>";  
print "Value return by print statement: ".$ret;   
?> 
Enter fullscreen mode Exit fullscreen mode

5.

<!DOCTYPE>  
<html>  
    <body>  
        <?php  
            echo "Hello world using echo </br>";  
            ECHO "Hello world using ECHO </br>";  
            EcHo "Hello world using EcHo </br>";  
        ?>  
    </body>  
</html>

Enter fullscreen mode Exit fullscreen mode

6.

<html>  
    <body>  
        <?php  
            $color = "black";  
            echo "My car is ". $ColoR ."</br>";  
            echo "My dog is ". $color ."</br>";  
            echo "My Phone is ". $COLOR ."</br>";  
        ?>  
    </body>  
</html>  
Enter fullscreen mode Exit fullscreen mode

7.

<?php  
$4c="hello";//number (invalid)  
$*d="hello";//special symbol (invalid)  

echo "$4c <br/> $*d";  
?>  

Enter fullscreen mode Exit fullscreen mode

8.

<?php  
    function local_var()  
    {  
        $num = 45;  //local variable  
        echo "Local variable declared inside the function is: ". $num;  
    }  
    local_var();  
?>  
Enter fullscreen mode Exit fullscreen mode

9.

<?php  
    function mytest()  
    {  
        $lang = "PHP";  
        echo "Web development language: " .$lang;  
    }  
    mytest();  
    //using $lang (local variable) outside the function will generate an error  
    echo $lang;  
?>  

Enter fullscreen mode Exit fullscreen mode

10.

<?php  
    $name = "Sanaya Sharma";        //Global Variable  
    function global_var()  
    {  
        global $name;  
        echo "Variable inside the function: ". $name;  
        echo "</br>";  
    }  
    global_var();  
    echo "Variable outside the function: ". $name;  
?>  
Enter fullscreen mode Exit fullscreen mode

11.

<?php  
    $name = "Sanaya Sharma";        //global variable  
    function global_var()  
    {  
        echo "Variable inside the function: ". $name;  
        echo "</br>";  
    }  
    global_var();  
?>  
Enter fullscreen mode Exit fullscreen mode

12.

<?php  
    $num1 = 5;      //global variable  
    $num2 = 13;     //global variable  
    function global_var()  
    {  
            $sum = $GLOBALS['num1'] + $GLOBALS['num2'];  
            echo "Sum of global variables is: " .$sum;  
    }  
    global_var();  
?>  

Enter fullscreen mode Exit fullscreen mode

13.

<?php  
    $x = 5;  
    function mytest()  
    {  
        $x = 7;  
        echo "value of x: " .$x;  
    }  
    mytest();  
?>  

Enter fullscreen mode Exit fullscreen mode

14.

<?php  
    function static_var()  
    {  
        static $num1 = 3;       //static variable  
        $num2 = 6;          //Non-static variable  
        //increment in non-static variable  
        $num1++;  
        //increment in static variable  
        $num2++;  
        echo "Static: " .$num1 ."</br>";  
        echo "Non-static: " .$num2 ."</br>";  
    }  

//first function call  
    static_var();  

    //second function call  
    static_var();  
?> 
Enter fullscreen mode Exit fullscreen mode

15.

<?php  
$x = "abc";  
$$x = 200;  
echo $x."<br/>";  
echo $$x."<br/>";  
echo $abc;  
?>  
Enter fullscreen mode Exit fullscreen mode

16.

<?php  
$name="Cat";  
${$name}="Dog";  
${${$name}}="Monkey";  
echo $name. "<br>";  
echo ${$name}. "<br>";  
echo $Cat. "<br>";  
echo ${${$name}}. "<br>";  
echo $Dog. "<br>";  
?> 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)