PHP for Absolute Beginners PHẦN 3

Tuyên bố trở lại trong PHP là hữu ích nhất trong các chức năng. Khi đạt được trong vòng một chức năng, trả lại ngay lập tức dừng lại việc thực hiện các chức năng và vượt qua đối số của nó là giá trị của cuộc gọi chức năng. Tôi sẽ bao gồm các tuyên bố trở lại trong phần của chương này được đặt tên | CHAPTER 2 UNDERSTANDING PHP LANGUAGE BASICS Running this loop creates the following output 0 2 4 6 8 10 return The return statement in PHP is most useful in functions. When reached within a function return immediately stops the execution of the function and passes its argument as the value of the function call. I ll cover the return statement in the section of this chapter named User-Defined Functions. If you use the return statement outside of a function the statement ends the execution of the script. Like echo and print return is a construct of the PHP language so no parentheses are required when you use it. include include_once require and require_once A great feature provided by PHP is the ability to load a script from an external file this makes it much easier to organize your code in larger projects. PHP provides four constructs you can use to load an external script include include_once require and require_once. The PHP manual recommends that developers use include_once and require_once because these constructs first check whether the file has already been loaded before either will load a given script. This saves resources and can increase the performance of your applications. Now let s take a look at an exercise that illustrates the power of loading external scripts. Fire up Eclipse and press Ctrl click or right-click your simple_blog project folder hover over New. and select File. from the drop-down menu. Name the new file and add the following code to the blank document that opens php foo green bar red Save the file then go back to our file and write the following code php include_once echo Variable foo has a value of foo br n echo Variable bar has a value of bar br n Download at 63 CHAPTER 2 UNDERSTANDING PHP LANGUAGE BASICS Save then navigate to http localhost simple_blog in a browser to see the results Variable foo has a value of green Variable bar has a value of red By including the file

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.