Introduction to PHP

PHP – Hypertext Preprocessor

04.01.2023 | Ilir Raufi | Blog, Development

PHP stands for Hypertext Preprocessor and it is a server side scripting language that is used to develop Static websites or Dynamic websites or Web applications. This server-side scripting language is commonly used in the back-end for tasks such as managing data on servers.

Prerequisites to learn PHP.

Learning a new programming language can be a bit overwhelming. Many people don’t know where to start and give up before they begin.One of the reasons for PHP’s success is that it has really great documentation. One can just dive into the documentation and get started without having any particular set of skills.

How to run PHP?

Manual installation of a Web server and PHP requires in-depth configuration knowledge but the XAMPP suite , makes it easy to run PHP.

XAMPP is a free and open source cross-platform web server solution stack package developed by Apache Friends that consists of the Apache HTTP Server, MariaDB & MySQL database, and interpreters for scripts written in the PHP and Perl programming languages. XAMPP stands for Cross-Platform (X), Apache (A), MariaDB & MySQL (M), PHP (P) and Perl (P). It is a simple, lightweight Apache distribution that makes it extremely easy for developers to create a local web server for testing and deployment purposes.

PHP Data Types.

  • PHP String: A string is a sequence of characters. In PHP, you can write the string inside single or double quotes.
  • PHP Integer: An integer data type is a non-decimal number . An integer must have at least one digit and can be either positive or negative.
  • PHP Float: A float is a number with a decimal point .
  • PHP Boolean: A Boolean represents two possible states: TRUE or FALSE. They are often used in conditional testing.
  • PHP Array:An array stores multiple values in one single variable. In the following example, the PHP var_dump() function returns the data type and value.

PHP Variables.

Variables are “containers” for storing information.In PHP, a variable starts with the $ sign, followed by the name of the variable,PHP has no command for declaring a variable, it automatically associates a data type to the variable, depending on its value. Since the data types are not set in a strict sense, you can do things like adding a string to an integer without causing an error.

PHP Variables Scope.

In PHP, variables can be declared anywhere in the script.

The scope of a variable is the part of the script where the variable can be referenced/used.

PHP has three different variable scopes:

  • Local: A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function.
  • Global: A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function. The global keyword is used to access a global variable from within a function.
  • Static: When a function is executed, all of its variables are deleted. But if you want any variable not to be deleted, the static keyword is used when you first declare the variable.
[contact-form-7 404 "Not Found"]