[go: up one dir, main page]

0% found this document useful (0 votes)
58 views10 pages

Unit 2 (Topic - 1)

The document discusses different types of arrays in PHP including indexed arrays, associative arrays, and multidimensional arrays. Indexed arrays use integers as keys and store elements by position. Associative arrays use strings as keys like a two-column table. Multidimensional arrays allow storing tabular data in an array of arrays like a matrix. The range() function creates arrays of consecutive values between two passed values like numbers or characters.

Uploaded by

Sneha Nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views10 pages

Unit 2 (Topic - 1)

The document discusses different types of arrays in PHP including indexed arrays, associative arrays, and multidimensional arrays. Indexed arrays use integers as keys and store elements by position. Associative arrays use strings as keys like a two-column table. Multidimensional arrays allow storing tabular data in an array of arrays like a matrix. The range() function creates arrays of consecutive values between two passed values like numbers or characters.

Uploaded by

Sneha Nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Subject: WBP-22619 Class: TYCM-Mac

CHAPTER 2: Arrays, Functions and Graphics In PHP


2.1 Creating and Manipulating Array, Types of Array-
Indexed, Associative & Multi-dimensional arrays
2.2 Extracting data from arrays, implode, explode and array flip
2.3 Traversing Arrays
2.4 Function and its types: User Defined function, Variable
Function, Anonymous Function
2.5 Operations on strings and String functions: str_word_count(),
strlen(), strrev(), strpos(), str_replace(), unwords(),
strtoupper(), strtolower(), strcmp()
2.6 Basic Graphics Concepts: Creating Images, Images with text,
Scaling Images, Creation of PDF Document
Mrs. M. P. Bhosale 1
Array and its Types:

• Array is used to hold multiple values of similar type in a


single variable.
• Types of Array:
1) Indexed Array
2) Associative Array
3) Multidimensional Array
Indexed Array:

• The keys of an indexed array are integers, beginning at 0.


• Indexed arrays are used when you identify things by their
position.
• There are two ways to define indexed array:

• Example:
1) $season=array("summer","winter","spring","autumn");

2) $season[0]="summer";
$season[1]="winter";
$season[2]="spring";
$season[3]="autumn";
Indexed Array:

• The keys of an indexed array are integers, beginning at 0.


• Indexed arrays are used when you identify things by their
position.
• There are two ways to define indexed array:
1) $season=array("summer","winter","spring","autumn");
2) $season[0]="summer";
$season[1]="winter";
$season[2]="spring";
$season[3]="autumn";
Indexed Array:

<?php

$season=array("summer","winter","spring","autumn");

echo "Season are: $season[0], $season[1], $season[2]


and $season[3]";

?>
Associative Array:

• Associative arrays have strings as keys and behave more


like two-column tables.
• The first column is the key, which is used to access the
value
• PHP internally stores all arrays as associative arrays; the
only difference between associative and indexed arrays is
what the keys used for.
Associative Array:
• We can associate name with each array elements in
PHP using => symbol.
• There are two ways to define associative array:
• Example:
1) $salary = array("Sonali"=>"350000",
"John"=>"450000","Kartik"=>"200000");

2) $salary["Sonali"]="350000";
$salary["John"]="450000";
$salary["Kartik"]="200000";
Associative Array:

<?php

$salary = array("Sonali"=>"350000",

"John"=>"450000","Kartik"=>"200000");

echo “Contents of salary array are: $salary[‘Sonali’],


$salary[‘John’], $salary[‘Kartik’];

?>
Multidimensional Array:
• PHP multidimensional array is also known as array of arrays.
• It allows you to store tabular data in an array.
• PHP multidimensional array can be represented in the form of
matrix which is represented by row * column.
• Syntax:
$emp = array
(
array(1,"sonali",400000),
array(2,"john",500000),
array(3,"rahul",300000)
);
Assigning a Range of Values: using range()
• The range() function creates an array of consecutive
integer or character values between and including the
two values you pass to it as arguments.
• For example:
$numbers = range(2, 5); // $numbers = array(2, 3, 4, 5);
$letters = range('a', 'z'); // $letters holds the alphabet
$reversedNumbers = range(5, 2);
// $reversedNumbers = array(5, 4, 3, 2);
• Only the first letter of a string argument is used to build
the range:
range("aaa", "zzz"); // same as range('a','z')

You might also like