This time I will show you how to use JSON as afunction parameter, what are theprecautionswhen using JSON as a function parameter, the following is a practical case, let’s take a look one time.
I have never understood json very well. I recently read some introductions and found out that this thing is so easy to use. Let me introduce it to you below
1. We can add / to a function at any timeDeleteparameters or add new parameters at any parameter position, unlike traditional parameters that must be written in the specified order, and each time a parameter of the function is added or deleted, the function content must be modified. When using JSON as a parameter, you don't need to consider the order of parameters.
Look at the following code demonstration:
The shortcomings of ordinary functions are obvious: the meaning and order of parameters must be remembered. This is not required when using JSON.
2. It is very convenient for users to call functions, especially when they only need to pass in a few or one of the parameters.
Look at the code demonstration below:
The advantages of the JSON method are obvious: you only need to pass in the required parameters each time, without considering other parameters.
JSON is really a useful thing. It does not need to be used in ajax or other aspects of js. It reflects its convenient and flexible characteristics. You should really dig into and learn json.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Summary of methods for converting JSON strings and JSON objects into each other
The above is the detailed content of How to use JSON as function parameter. For more information, please follow other related articles on the PHP Chinese website!