Checking for Existence and Emptiness in PHP

phpclassroom007

Situations often arise when you need to check for the existence or emptiness of a variable. PHP provides the isset () , empty () and array_key_exists () functions for this . Checking for the existence of a variable The isset () function returns true if

Custom Functions in PHP

phpclassroom007

PHP allows developers to create their own functions. Creating functions The creation of the function looks like this: First, the function keyword is written , then the name of the function (the naming rules are

Built-in Functions in PHP

phpclassroom007

PHP has a huge number of built-in functions like var_dump () ,  print_r () , unset () , phpinfo () , etc. To call a function, you need to write parentheses after its name: It’s pointless to try to

Interrupting Loops in PHP

phpclassroom007

Aborting an iteration – continue The continue statement allows you to skip one iteration without interfering with the further execution of the loop: Result in the browser: Breaking the loop – break The break statement breaks the loop: Result

PHP FOR Loop

phpclassroom007

The for loop is considered to be the most complex of PHP loops, but it is the most functional and used quite often. You can pass 3 expressions to the for loop. The

DO WHILE Loop in PHP

phpclassroom007

The while loop is also called the “precondition loop” because we first check the condition for true and then execute the code. Unlike while, a do-while loop or a “postcondition loop” first

WHILE Loop in PHP

phpclassroom007

The WHILE loop runs as long as the parenthesized expression evaluates to true . Let’s take an example: you need to display numbers from 1 to 10. Using the while loop, this problem can

FOREACH Loop in PHP

phpclassroom007

FOREACH Loop Syntax Using the FOREACH loop, we can iterate over all the elements of the array and perform some action on them (or just some of them). For example, the output

Converting Arrays in PHP

phpclassroom007

Convert string to array To split strings, there is an explode () function , into which you need to pass the string itself and the symbol by which it will split: Result in the browser:

Concatenating Arrays in PHP

phpclassroom007

You can combine multiple arrays using the array_merge () function , it can accept an unlimited number of arrays: If the arrays have the same numeric keys, then both values ​​will be preserved. But if