PHP Core Syntax Summary

Source: Internet
Author: User
Tags php language learn php

These days to learn PHP core programming syntax, PHP core syntax is not much summed up, roughly divided into PHP tags, syntax specifications, data types, variables, constants, and of course, predefined, as well as operators, follow the bad and so on, the last few days to learn the function, where the array of common functions are very many. For example, Array_merge, Rand, Asort, and Arsort are more likely to be used in future projects.

The functions of the array, foreach () and While-list-each () two are the most powerful function to iterate the array, not only can solve the problem of accessing the array, and its return value has its own characteristics, it can be flexibly used in the processing of database data in the future.

At ordinary times the application of the PHP language, I think the more difficult is recursion, it is more difficult to understand than the iteration, the principle of iteration and commonly used for the following bad, but recursion is not the same, recursion is difficult in how to define the export of recursion, when the definition, the definition of the conditions should be how, like " Fibonacci Series "That classic title:

<?php

/**
* Fibonacci sequence
* @param int $n Number of entries for the series
* @return int $s The value of the last item of the sequence
*/
function f ($n) {
//recursive exit
if ($n = = 1 | | $n = = 2) {
return 1;
"
//recursion point
$s = f ($n-1) + F ($n-2);
return $s;
}
//call function and output
echo f ($_get[' n ')");

Just encounter recursion when the arithmetic problem, in the recursive exit there is a little mixed, mainly reaction to the recursive point of f ($n-1) and F ($n-2) The value of the two function calls how to find out, even if you know that it is a layer down to the N=1 and 2 will return a value, and then the computer to calculate backwards , but at first I was caught in my own bad understanding, that is, the recursive point of the two functions back after the calculation of how. But then, I thought about it several times at lunchtime, figuring out that when N is assigned to a formal parameter, it does not satisfy the export condition, then it becomes n-1 and n-2 two numbers, but these two numbers are unknown, only the value of N=1 and n=2 is the determined 1, so you can only continue to call the function, Re-n-1 to the function parameters, then n-1, will become n-2 and n-3 the sum of the two values, and then continue to finally solve the function of the recursive point of the real meaning, of course, the recursive export is a very important logic problem, although not know that the work will not be used much, But I will continue to explore the recursive invocation of functions, because this point gives me a lot of questions and curiosity, how can I handle all kinds of problems?

PHP Core Syntax Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.