PHP Lessons # 3 | Printing Functions and Usage Areas

Discussion in 'Web Programming' started by hbkyatty, Apr 11, 2018.

  1. hbkyatty

    hbkyatty New Member

    Hello Friends, I am
    with you in my 3rd Php course. Today in PHP you will also recognize a few print / output functions that you will recognize from other coding languages, and we will look at the differences between them.

    1. echo The
    echo command is one of the most basic commands in PHP. It is so simple to use that we already see it at the beginning of each PHP class.

    Example of use: echo "Hello World";

    We printed the "Hello World" text on the screen. And our process is dotted here. No value will be returned indicating that the operation is complete.

    : The function will return true (1) if the operation is completed, false (0) if it is not completed. But there is no such thing as an echo. I will come now what it is.

    2. print ();
    Essentially, the print and echo functions are identical. There is only a slight difference in print, when the print is successful on the screen, this function takes true (1) (ie returns). If it fails, it gets false (0).

    Example of use: print "Hello World";

    Now, let's face it with echo. We will also understand the spin on this. In PHP, all functions except echo are true if the operation is completed, true (1), false if the operation is not completed, false (0). We can show this with a simple algorithm.

    if (print ("Hello World"))
    {
    echo "- operation succeeded";
    }
    else
    {
    echo "- Operation failed";
    }

    Now the screen will show us the following output: "Hello World - The operation is successful".

    Here we said that if the print function gets true (1), that is, if the operation completes successfully, we print the process success text - to the screen. If it can not, ie, if it gets false (0), we print the text "Operation failed".

    So if our print function could not work because of a possible reason, we would see the message "Failure - operation failed".

    This also applies to other functions. So I tried to explain the difference between here and echo.

    3. print_r ();
    This has a feature that is not in print and echo. With this function, we can display arrays, that is, arrays with an opening. The Array has not arrived yet, so if you do not know the array yet, this function is not a problem for you.

    Example of use: print_r $ array;

    If we were trying to print an array on the screen with the print or echo command, we would get a br error message on the page and see the word "Array" under it. The reason for this is that the echo and print functions do not expose themselves as arrays. However, you can select an element in the circle and only show that element.

    But in print_r, we can show all the elements of the array together with their element id. For this we only need to use the print_r <array> formula.

    A sample output of the print_r function:([0] => 1, [1] => 2)

    Yes, this is the end of our lesson.
    I hope I can tell you well.

    Easy work, good work.
     

Share This Page