Home » Programming » PHP

How to Declare Variables in PHP (Constants, Static, Global)

PHP Declare Variable

This article shows you how to declare variables in PHP, including constant, static, and global variables. Code examples are provided. What is a Variable? In computer programming, a variable stores a value, giving it a name that can be used to access it. Once a variable has been created and a value has been assigned to it, the value can be retrieved using the name given to the variable. The value of a variable can be updated (unless the variable has been declared as a constant), and the … Read more

Categories PHP

Home » Programming » PHP

Safely Using PHP Variable Variables with Arrays [Examples]

PHP Variable Variables and Arrays

PHP variable variables are a powerful way to add flexibility to your code. This article explains the pitfalls and solutions to using them with arrays. Variable variables are a great way to simplify your code and make it more readable. However, when using them with arrays, you need to be careful. PHP Arrays and Variable Variables To use variable variables with PHP arrays, extra considerations need to be taken to resolve potential ambiguities in your code. Consider the following PHP code: To what exactly is the array key … Read more

Categories PHP

Home » Programming » PHP

PHP Scopes in Functions, Loops, Modules, With Examples

PHP Variable Scopes

This article explains what variable scopes are, and how they work in the PHP programming language, with code examples. When programming in any language, you must be aware of how variables are scoped – otherwise, you risk unexpected behaviour, including incorrect calculations, or loss of data – detrimental outcomes for any application (especially if you are working with business records or financial data) that will result in angry users. What is a Variable? In computer programming, a variable stores a value, giving it a name that can … Read more

Categories PHP

Home » Programming » PHP

PHP $this Variable – What It Is, How To Use It [Examples]

PHP this

This article will explain the PHP $this variable – what it is, what it does, and how to use it – with code examples. PHP Objects and Classes PHP is an object-oriented programming language. Code and data can be stored in an object which represents the items your code represents with a set of properties and methods. For example, you might have objects that represent sales invoices, or cars, or pets, or people – each containing code and data relevant to the thing they represent. The properties or attributes of … Read more

Categories PHP

Home » Programming » PHP

How to Use Variable Variables in PHP, with Examples

PHP Variable Variables

Variable variables let you dynamically access variables by their name. Sound confusing? This article will explain PHP variable variables, and provide code examples. What is a variable? In computer programming, variables store a value, or reference to a value, for later use. Variables have names, and when you access a named variable, the value it contains can be read or updated. Declaring variables in PHP In PHP, a variable is declared when it is first used: Above, a variable named $myVariable is declared using the = (equals) operator, and assigned the … Read more

Categories PHP

Home » Programming » PHP

Using PHP sleep() and usleep() to Pause Execution [Examples]

Pausing PHP with sleep and usleep

This short tutorial will show you how to use the PHP sleep() and usleep() functions to pause script execution for a number of seconds/microseconds, and provide some code examples. The PHP sleep() and usleep() functions both pause execution of the script, but both behave a bit differently. Why Pause/Sleep PHP Script Execution? Delaying, sleeping, or pausing PHP script execution is commonly used when scheduling an event. A call to the sleep() function might be placed at the end of a loop, so that after the code inside the loop has been run, a certain amount of time … Read more

Categories PHP

Home » Programming » PHP

How to Use Single/Multiline Comments in your PHP Code

PHP Code Comments

This article will quickly walk you through how to comment your PHP code with single and multi-line comments. What is a Comment? A comment in programming is one or more lines of text that aren’t interpreted as programming instructions. Instead, the computer skips the commented lines when executing your code, completely ignoring them. Comments don’t have to conform to any valid syntax. They’re just text that you read, and the computer doesn’t. Comments can span single or multiple lines. Single Line Comments Single line comments are any lines of … Read more

Categories PHP

Home » Programming » PHP

PHP vs Ruby – Which One should I Pick for my Project in 2022?

PHP vs Ruby

This article will explain what the PHP and Ruby programming languages are, what they’re best used for, and which one you should pick up in 2022. What is PHP? PHP: Hypertext Preprocessor. PHP a recursive initialism that contains its own name, just to make things confusing for you: P PHP H Hypertext P Preprocessor PHP is a processing language – it can search, calculate, and do things based on logical conditions. PHP usually outputs the information it has processed via HTTP – as a web page, … Read more

Categories PHP

Home » Programming » PHP

PHP vs Python: Which Should You Learn In 2022? What’s the Difference?

PHP vs Python

This article will explain what the PHP and Python programming languages are, where they’re best used, and which one is most useful in 2022. What is PHP? PHP: Hypertext Preprocessor. PHP a recursive initialism that contains its own name, just to make things confusing for you: P PHP H Hypertext P Preprocessor PHP is a processing language – it can search, calculate, and do things based on logical conditions. PHP usually outputs the information it has processed via HTTP – as a web page, or as formatted data to be … Read more

Home » Programming » PHP

Deleting Files in PHP with unlink() [Examples]

PHP Delete File with unlink()

This article will show you how to delete a single file or multiple files in PHP using the unlink() function, and provide code examples. Once you have file uploads working in PHP, you may want to allow your users to delete files they no longer wish to keep. Read on to find out how. There is no PHP Function called ‘Delete’ To clear up any confusion, unlink() is the function for deleting files in PHP. There is no built in PHP function called delete(). If you’re looking to delete a directory in PHP, … Read more

Categories PHP