PHP, like any other language has a set of useful functions out of the box. All of them are part of so-called standard library. It usually contains thousands of functions that are impossible to memorize, and you don’t need to do so. It is assumed that any programmer knows where to find documentation on them and has an idea of what he wants his code to do. All he has to do is to find an appropriate function for it. It’s extremely difficult to code without access to internet.
For beginners, it usually sounds very confusing. They don’t know what to look for, because they don’t know anything at all. Funny enough, there is no way to know everything you need to know. Any developer in the process of his professional growth explores more and more interesting functions that accomplish his tasks in a more elegant way, extending this way his knowledge base.
Here are some tips on how to explore new functions:
*Always be aware of what type of data you are working with. You will most likely find the desired function in the corresponding section of the documentation. If you work with strings, for example, search for functions that work with strings.
- Once in a while open the function reference and read it focusing on functions’ signature and usage.
- Read other people’s code more often, especially that of libraries you use. It is available on GitHub.
One more thing to know about standard PHP functions is that they are globally accessible. In other words, you can call them at any place in your program (it doesn’t work the same way with functions you write yourself). Most standard library functions are focused on functionality of some data type. For example, there are functions that operate with strings, numbers etc. We will study some of them in this course.
gettype function defines the type of the argument we pass in it. The type name is returned as as a string.
gettype(10) will return
"integer" - the integer number type.
Print to screen the type of the variable
Standard library — a set of useful functions a programming language has out of the box.
Please sign in with your GitHub account, this is necessary to track the progress of the lessons. If you do not have an account yet, now is the time to create an account on GitHub.