Hướng dẫn can we create our own functions in php? - chúng ta có thể tạo các hàm của riêng mình trong php không?

This chapter is from the book

Creating and Calling Your Own Functions

As you've already seen, PHP has a lot of built-in functions, addressing almost every need. More importantly, though, it has the capability for you to define and use your own functions for whatever purpose. The syntax for making your own function is

function function_name [] {
   // Function code.
}

The name of your function can be any combination of letters, numbers, and the underscore, but it must begin with either a letter or the underscore. The main restriction is that you cannot use an existing function name for your function [print, echo, isset, and so on].

In PHP, as I mentioned in the first chapter, function names are case-insensitive [unlike variable names], so you could call that function using function_name[] or FUNCTION_NAME[] or function_Name[], etc.

The code within the function can do nearly anything, from generating HTML to performing calculations. In this chapter, I'll demonstrate many different uses.

To create your own function

  1. Create a new PHP document in your text editor [ Script 3.7].

Bài Viết Liên Quan

Chủ Đề