php-mysql tutorial

Designed By NISHANT GUPTA

  • Home
  • PHP
  • HTML
  • CSS
  • JavaScript
  • JQuery
  • Contact-us
  • Learn HTML

    • Introduction of HTML
    • Image Handling in HTML
    • List Handling in HTML
    • Font Handling in HTML
    • Table Handling in HTML
    • Form Handling in HTML
  • Learn CSS

    • Introduction of CSS
    • Styling Background in CSS
    • Styling Text in CSS
    • Styling Font in CSS
    • Styling Link in CSS
    • Styling List in CSS
    • Styling Table in CSS
    • Styling Div in CSS
    • Styling Span in CSS
    • Positioning in CSS
    • Display in CSS
  • Learn JavaScript

    • Introduction of JavaScript
    • Data Type in JavaScript
    • Variable in JavaScript
    • Oprator in JavaScript
    • Cond. Statement in JavaScript
    • Loop in JavaScript
    • Array in JavaScript
    • Function in JavaScript
    • Date in JavaScript
    • String in JavaScript
    • DOM in JavaScript
    • Event Handling in JavaScript
    • Form Handling in JavaScript
  • Learn PHP-MYSQL

    • Introduction of PHP
    • Decision Control in PHP
    • Loop in PHP
    • Array in PHP
    • Function in PHP
    • Form Handling in PHP
    • File Inclusion in PHP

Array in PHP

Array Introduction

An array in PHP is same as JavaScript as it can hold more than one value at a time.

In PHP, the array() function is used to create an array:

array();

Types Of Arrays

In PHP, there are three types of arrays:

  1. Indexed arrays - Arrays with numeric index

  2. Associative arrays - Arrays with named keys

  3. Multidimensional arrays - Arrays containing one or more arrays

Indexed Arrays

Indexed arrays can be declared in 2 ways:
  1. Let PHP assign the index automatically   (index always starts at 0)
Example

$seasons=array(“Summer”,”Winter”,”Rainy”);

  1. Assign the index manually.
Example

$seasons[0]=“Summer”;

 $seasons[1]=“Winter";

 $seasons[2]=“Rainy";

Accessing Indexed Arrays

To access array elements we can use their index

Example

$seasons=array(“Summer”,”Winter”,”Rainy”);

echo $seasons[0] . “<br>”;

echo $seasons[1] . “<br>”;

echo $seasons[2] . “<br>”;

Using The count( ) Function

The count() function is used to return the length (the number of elements) of an array:
Example

<?php
$seasons=array(“summer“,”winter”,”rainy”);
echo count($seasons);
?>

Advertisements

 

©  2014 All Rights Reserved  •  Design by >Nishant Gupta.

Privacy Policy • Terms of Use