PHP – Array functions PHP has a very comprehensive list of built-in functions to work with arrays. Please take into consideration that working with big and complicated arrays take a lot of memory usage. You can recycle that memory just by destroying the array if you do not need it anymore. Here are some …
PHP – Multidimensional arrays A multidimensional array is the same as in any other programming language: an array containing one or multiple other arrays. Multidimensional arrays are a very useful concept while. Although you will normally find and use two or three levels of multidimensional arrays, you can have as many levels as you like …
PHP – Superglobal arrays Superglobals are a type of variables that are aveilable from any part of your code. Some are well known like POST and GET that are used to pass form values and COOKIE and SESSION that are used to store specific information for a later use. Here are all the superglobals that are all available for you to use …
PHP – Array loop Iterate array with foreach() The main PHP built-in function used to iterate through array elements is foreach(). We learned about the foreach() loop in a dedicated tutorial. Here is an example of how to loop through an array using foreach. PHP <?php $file_list = array( “index” => “home_page.php”, “article” => “article_page.php”, “about” => …
PHP – Arrays An array is a type of data structure that allows you to store multiple values inside of a variable, on a key-value basis. Here is a simple example of an array in PHP. PHP $product = array(“milk”, “bread”, “potato”); echo “Please buy ” . $product[0] . “, ” . $product[1] . …
PHP – Foreach loop The PHP foreach loop is native function that loops a piece of code for each key/value of an array until it reaches the last array element. It only works on an array, so do not try this with expressions, or any other type of values of a variable other than arrays. Here …
PHP – For loop If you want to execute a loop for a given number of times, the for statement is what you are looking for. Here is a simplified example of the for syntax for (start counter; check current counter value; increment counter) { # run this code } Although this is a simplified form …
PHP – While and do-while The PHP while statement is used to run a code in loop over and over again. This is very useful and helps you minimize the code for rapid edition and maintenance. There are several loop statements that can be used depending on your needs while – repeats a block of code as …
PHP – Switch The PHP switch statement (native function) executes a different piece of code depending on the value of a variable (or expression). Here is a simplified version of the PHP switch syntax: PHP switch (expression) { case value_1: // case expression = value_1 break; case value_2: // case expression = value_2 break; …
PHP – If / Else statement The if/else condition is the most simple form of conditional processing and you will find it in any programming language. So if you already know some other programming language this will be an easy read. If not, just read this tutorial carefully because it will be useful when …
PHP – Strings A string in PHP is a simple character concatenation like “Hello world!”, “Lorem Ipsum…” etc. We already learned about how to set a string in PHP using double and single quotes, nowdoc and heredoc syntax. Strings are one of the most used types of data. The simplest way to assign string values is …
PHP – Data types PHP like most other programming languages supports various data types. It is very important to understand that variable cand act in a distinct way depending on the type of data they contain. Here are all data types that PHP is using: String – Simple text surrounded by commas Integer – …