arrays php 03

16
PHP Course 3: Arrays An array stores multiple values in one single variable PHP Course [email protected]

Upload: it-big-dig

Post on 22-May-2015

326 views

Category:

Education


3 download

DESCRIPTION

PHP lecture 03 PHP Array Functions PHP Array Functions overview. count() - return the number of elements of an array. sort() - sort arrays in ascending order. For Loop

TRANSCRIPT

Page 1: Arrays PHP 03

PHP Course3: Arrays

An array stores multiple values in one single variable

PHP Course [email protected]

Page 2: Arrays PHP 03

Instructor Name: Mohamed Saad.

Email: [email protected]

Occupation: Web Developer In IT Big Dig.

PHP Course [email protected]

Page 3: Arrays PHP 03

Contents• PHP Array Functions

o PHP Array Functions overview.o count() - return the number of elements of an array.o sort() - sort arrays in ascending order.

• For Loop

PHP Course [email protected]

Page 4: Arrays PHP 03

PHP Array Functions overview

o count() - return the number of elements of an array.

o sort() - sort arrays in ascending order.

o rsort() - sort arrays in descending order.

o asort() - sort associative arrays in ascending order,

according to the value.

o ksort() - sort associative arrays in ascending order,

according to the key.

o arsort() - sort associative arrays in descending order,

according to the value.

o krsort() - sort associative arrays in descending order,

according to the key.

Page 5: Arrays PHP 03

PHP Array• There are three types of arrays:

•Arrays with numeric indexIndexed arrays

• Arrays with named keysAssociative arrays

•Arrays containing one or more arrays

Multidimensional arrays

Page 6: Arrays PHP 03

array() FunctionSyntax

•array(‘value’, );indexed

•array(‘key’ =>’value’, );

associative

Page 7: Arrays PHP 03
Page 8: Arrays PHP 03

count() FunctionSyntax

o $x=array("Volvo“,"BMW“,"Toyota");

echo count($x);

Page 9: Arrays PHP 03

sort() Function

Page 10: Arrays PHP 03

<?php$x=array("Volvo","BMW","Toyota","Audi");sort($x);

$var_count=count($x);for($i=0;$i<$var_count;$i++) { echo $x[$i]; echo "<br>"; }?>

Copy Codearray1.php

PHP Course [email protected]

Page 11: Arrays PHP 03

For LoopSyntax

o for (Counter; condition; increment)  {  code to be executed;  }

PHP Course [email protected]

Page 12: Arrays PHP 03
Page 13: Arrays PHP 03
Page 14: Arrays PHP 03

Loop Through an Indexed Array

Page 15: Arrays PHP 03

<?php$cars=array("Volvo","BMW","Toyota");$arrlength=count($cars);echo $arrlength,"<br>";for($x=0;$x<$arrlength;$x++) { echo $cars[$x]; echo "<br>"; }?>

Copy Codefor.php

PHP Course [email protected]

Page 16: Arrays PHP 03

We hope You enjoy This Tutorial.

For any Suggestions Please Email Us

[email protected]

PHP Course [email protected]

EndArrays