Tag: php

PHP Installation

How to set up PHP on Your Own PC:

  • install a web server
  • install PHP
  • install a database, such as MySQL

Instead of installing each software individually, we can use the combined environment package. There are various development environments available that can install Web-server/PHP/MySQL easily at once.

XAMPP is the most popular PHP development environment. XAMPP is a completely free, easy to install Apache distribution containing PHP, MySQL and Perl. The XAMPP open source package has been set up to be incredibly easy to install and to use.

Learn PHP Installation step by step using XAMPP

To install XAMPP in windows, first you need to download the XAMPP installer for windows.

  1. To download the XAMPP installer for windows, visit the URL https://www.apachefriends.org/download.html.
  2. Go to the "Download" section in the page. Here, you will see XAMPP for Windows, Linux, and Mac OS X. We can easily download the XAMPP installer for Windows.
  3. Click on the Download link to download XAMPP as shown below. (Recommended XAMPP 5.6)
  4. After downloading the installer, double click on the downloaded executable (.exe) file to start the XAMPP installation process. Click Yes, if User Account Control dialog box appears.
  5. You should avoid installing XAMPP to C:\ Drive. Because when your reinstall windows, all you C drive project data will be lost. Change installation directory to "D:\" or any other directory/drive.
  6. Click Next & Follow instructions if any.
  7. You will see the installation progress. Please wait for all the process to complete. Then, click Finish to finish the installation process.
  8. The dialog box asks: Do you want to start the Control Panel now? You can choose to start the Control Panel now.
  9. If the XAMPP control panel is not already started, find the XAMPP control panel in the start menu or its desktop icon, right click on it and select "Run as administrator". Click "Yes" on the "User Account Control" popup, and wait for the XAMPP control panel to start. You will see the XAMPP control panel running.
  10. Click on the Start button next to Apache, and wait for Apache to start. After the Apache has started, click on the Start button next to MySQL. Wait for MySQL to start. Both Apache and MySQL are running now.
  11. Now, your PHP installation is done and you can run your first PHP program.

To Run a PHP program, create your first program using Next Chapter

Important Link: How to Install XAMPP for Windows: 10 Steps (with Pictures)

PHP Arrays

PHP array is a linear data structure that can store more than one values under a single variable.

Types of Arrays

There are three different kind of arrays and each array value is accessed using an ID, which is called array index.

  • Numeric/Indexed Array − An array with a numeric index. Values are stored and accessed in linear fashion.
  • Associative array − An array with strings as an index. This stores element values in association with key values rather than in a strict linear index order.
  • Multidimensional array − An array containing one or more arrays and values are accessed using multiple indices.

Numeric/Indexed Array

An indexed or numeric array stores each array element with a numeric index.

$fruit = array("Mango", "Papaya", "Orange");
echo "I would like to eat " . $fruit[0] . ", " . $fruit[1] . " and " . $fruit[2] . "."; 

Run : http://ideone.com/OuXU3A

[tc_output_window] I would like to eat Mango, Papaya and Orange. [/tc_output_window]

Associative Arrays

The associative arrays are very similar to numeric arrays in term of functionality but they are different in terms of their index. Associative array will have their index as string so that you can establish a strong association between key and values.

$age = array("Symntha"=>"15", "Clan"=>"17", "Smith"=>"23");
echo "Symntha is " . $age['Symntha'] . " years old.";

Run : http://ideone.com/BFRnAf

[tc_output_window] Symntha is 15 years old. [/tc_output_window]

Multi-dimensional Array

A multi-dimensional array each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. Values in the multi-dimensional array are accessed using multiple index.

$cars = array
echo $cars[0][0].": In stock: ".$cars[0][1].", sold: ".$cars[0][2].".\n";
echo "<br>";
echo $cars[1][0].": In stock: ".$cars[1][1].", sold: ".$cars[1][2].".\n";

Run : http://ideone.com/0o2e9P

[tc_output_window] Elentra: In stock: 22, sold: 18. Audi: In stock: 15, sold: 13. [/tc_output_window]