In this tutorial, I'll help you get started with learning the basic concepts of PHP so that you can use it to build whatever kind of web apps you want.
The code you write in PHP will have to go inside a PHP file. This means that you need to have a basic understanding of what a PHP file is and what it does.
The fact that you can mix PHP and HTML to quickly create a functional website makes PHP one of the most beginner-friendly ways out there to develop a website. Learn how to use HTML within PHP.
Reading the above posts should help you get a rough idea of where and how you can write your own PHP code. Let's dive into the basics now.
PHP and Numbers
Many web development projects will require you to do at least some kind of mathematical computation. I've already written a few tutorials on this topic to help you cover the basics.
- PHP Integers, Floats and Number Strings—Read this to understand how PHP handles different kinds of numbers and the basic difference between them.
- Trigonometry, Random Numbers and More With Built-in PHP Math Functions—PHP also comes with a lot of built-in functions that can help you generate random numbers or calculate the values of trigonometric angles. This tutorial also shows you how to apply this knowledge of trigonometric functions to create basic circular design patterns.
- How to Use the Modulo Operator in PHP—This tutorial will show you some practical applications of the modulo operator when dealing with numbers in PHP.
- PHP Integers, Floats, and Number StringsMonty Shokeen28 Dec 2020
- Trigonometry, Random Numbers and More With Built-in PHP Math FunctionsMonty Shokeen12 Oct 2018
- How to Use the Modulo Operator in PHPMonty Shokeen30 Nov 2020
Arrays in PHP
Arrays are useful for a lot of things. You usually use them to store elements of the same kind together under one name. However, they can store almost anything you want. Arrays in PHP can be very simple with numerical indices or multi-dimensional and associative with non-numeric keys.
Here's a curated list of tutorials to help you learn the basics of arrays in PHP and how you can use a variety of PHP functions to work more efficiently with arrays.
- Understanding Arrays in PHP—Read this post to learn about different types of arrays and common array functions in PHP.
- Working with PHP Arrays in the Right Way—This tutorial will teach you about a bunch of functions and tricks that you can use to write more succinct code when dealing with PHP arrays.
- How to Sort Arrays in PHP—It is almost inevitable that you will have to sort your data in some way when working with arrays. This tutorial will teach you different ways of doing exactly that. You will learn how to sort arrays by values or keys. It also explains how to sort multi-dimensional arrays or sort with user-defined functions.
- Get the First and Last Elements of an Array in PHP—You will frequently need to access items at either the beginning or the end of an array in PHP. This tutorial will teach you how to access them without needing to know their keys.
- Understand Arrays in PHPSajal Soni31 Jan 2022
- Working With PHP Arrays in the Right WayAnton Bagaiev27 Oct 2020
- How to Sort Arrays in PHPMonty Shokeen30 Jun 2022
- Get the First and Last Elements of an Array in PHPMonty Shokeen19 Apr 2021
Strings in PHP
You're probably already familiar with strings if you have done programming in other languages. PHP comes with a huge set of built-in functions that can help you accomplish a lot of common tasks very easily.
Here are a bunch of tutorials that explain how to do different tasks using these string functions in PHP.
- How to Join Strings in PHP—This is a quick tip post to show you how to prepend, append, or join the text somewhere in the middle of a string in PHP.
- How to Trim Strings in PHP—Different strings that you deal with will probably have some unwanted text that you want to remove. This post will show you how to do that in different scenarios.
- How to Replace Strings in PHP—This tutorial will teach you how to replace a substring with some other text using a variety of options.
- Generate Random Alphanumeric Strings in PHP—Read this tutorial if you are curious about generating random alphanumeric strings for usernames and passwords using built-in functions in PHP.
- String Concatenation in PHPMonty Shokeen30 Jan 2021
- How to Trim Strings in PHPMonty Shokeen28 Jan 2021
- How to Replace Strings in PHPMonty Shokeen25 Mar 2021
- Generate Random Alphanumeric Strings in PHPMonty Shokeen23 Nov 2020
Learn More Basics
We can move on to some other miscellaneous topics now that you know how to handle numbers, arrays, and strings in PHP. Here are a bunch of tutorials that cover a wide range of topics.
is_null()Functions in PHP—You will have to deal with a fair share of variables which are unexpectedly either not set or empty. This post will help you understand how to differentiate between them and proceed accordingly.
Using the PHP Switch Statement—Read this post to learn how you can use the switch statement as a replacement for complicated
Crash Course in the PHP Ternary Operator—This tutorial will help you write shorter code to replace a simple
- Understanding PHP Constructors—Consider reading this beginner-friendly tutorial about constructors if you are looking into starting your OOP journey with PHP.
- PHP isset() vs. empty() vs. is_null()Monty Shokeen11 Jun 2021
- Using the PHP Switch StatementSajal Soni15 Jun 2021
- Crash Course in the PHP Ternary Operator With ExamplesSajal Soni27 May 2021
- Understanding PHP ConstructorsSajal Soni20 Jul 2021
Some "How To" Tutorials
There are a lot of other topics that you could learn about to get a better understanding of how to do things in PHP. This section contains a small list of such posts which don't fall inside a specific category.
- How to Compare Dates in PHP—Follow this tutorial to learn how you can compare and find the difference between two given dates in PHP.
- How to Work With Cookies in PHP—It is important that you have a basic understanding of handling cookies in PHP when creating websites. This tutorial will help you get a quick head start.
- How to Use Sessions and Session Variables in PHP—Read this tutorial if you want to learn about sessions in PHP. It also briefly discusses the difference between sessions and cookies.
- How to Parse JSON in PHP—JSON is a popular format for passing around information. This tutorial will teach you how to read JSON from a file in PHP and how to create your own JSON.
- How to Compare Dates in PHPMonty Shokeen10 Jul 2021
- How to Work With Cookies in PHPSajal Soni16 Feb 2021
- How to Use Sessions and Session Variables in PHPSajal Soni16 Feb 2021
- How to Parse JSON in PHPMonty Shokeen31 May 2021
Learn PHP With a Free Online Course
If you want to learn PHP, check out our free online course on PHP fundamentals!
In this course, you'll learn the fundamentals of PHP programming. You'll start with the basics, learning how PHP works and writing simple PHP loops and functions. Then you'll build up to coding classes for simple object-oriented programming (OOP). Along the way, you'll learn all the most important skills for writing apps for the web: you'll get a chance to practice responding to GET and POST requests, parsing JSON, authenticating users, and using a MySQL database.
Learning is a continuous process. In this article, my aim was to help you get started by listing different tutorials that cover a variety of related topics. Reading them should help you gain a basic understanding of the PHP language. However, there are always more topics to learn and explore. Search Envato Tuts+ for much more about learning PHP!
Hopefully, all these tutorials will help you learn how to create something practical by writing your own PHP code.