Sharp Tutorial
Array in php

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

PHP Introduction

  • PHP home
  • PHP introduction
  • How to install and run
  • Syntax and Rule in PHP
  • Data type and operator
  • If else in php
  • Loop in php
  • Array in php
  • Sring in php
  • Function in php
  • Include in php

Working with Forms

  • Get and Post
  • Get Form input into PHP
  • Form Validation

PHP with MySQl

  • Connect PHP & Mysql
  • Insert using PHP Mysql
  • Select using PHP MySql
  • Delete Update using PHP Mysql
  • Login Page Example in PHP

Advanced PHP

  • Session in PHP
  • Cookies in PHP
  • File Handling in PHP
  • File Upload/Download PH

Object Oriented PHP

  • Class Obejct in PHP
  • Constructor in PHP
  • Destructor in PHP
  • Inheritance in PHP

Array in PHP

PHP Array used to store the multiple values of similar type in a single variable. In PHP array may be declared as following.

$course=array(“bca”,”BE”,”Btech”);

There are 3 types of array in php

1 Indexed Array

2 Associative Array 

3 Multidimensional Array.

PHP Program on indexed PHP Array

 <html>
<body bgcolor="grey">
<center>
<?php
$city=array("delhi","new york" ,"london");
// following display all city and count function gives the length of array.
for($i=0 ;$i<(count($city));$i++)
{
echo"<br> $city[$i]";
}
?>
</center>
</body>
<html>

Output of the above program is as follows

Associative Array in PHP

PHP Associative Array used to store values in pair with key and value as following.

$student=array(“name”=>”john”, “course”=>”Btech”);

 <html>
<body bgcolor="grey">
<center>
<?php
$emp=array("empId"=>"101","empName"=>"Ram","dept"=>"IT");
// Now we can print the array values with keyname

echo"empId=".$emp['empId']."EmpName=".$emp['empName']."dept=".$emp['dept'];
?>
</center>
</body>
</html>

Output of the above program is as follows

Multi dimensional Array in PHP

PHP Multi Dimensional Array is an array of array and may be defined as in  following php program. in which 3 employee details stored in a single array.

 <html>
<body bgcolor="gray">
<center>
<?php
$employees=array(
array(101,"ram","HR"),
array(102,"shyam","IT"),
array(103,"ghanshaym","Account")
);
for($i=0; $i<3; $i++) //loop to print all three records)
{
echo "<br>Empid=".$employees[$i][0]." name=".$employees[$i][1]." Dept=".$employees[$i][2];
}
?>
</center>
</body>
</html>

Output of the above program is as follows

Enquiry about Course

Ask your Question

Click Here

Sharp (2) Tutorials

Video/ C Introduction

Watch video in full size

Video tutorial

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial