arrays php 03

Post on 22-May-2015

326 Views

Category:

Education

3 Downloads

Preview:

Click to see full reader

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

PHP Course3: Arrays

An array stores multiple values in one single variable

PHP Course Info@ITBigDig.com

Instructor Name: Mohamed Saad.

Email: Engsaad_aly@hotmail.com

Occupation: Web Developer In IT Big Dig.

PHP Course Info@ITBigDig.com

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 Info@ITBigDig.com

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.

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

array() FunctionSyntax

•array(‘value’, );indexed

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

associative

count() FunctionSyntax

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

echo count($x);

sort() Function

<?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 Info@ITBigDig.com

For LoopSyntax

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

PHP Course Info@ITBigDig.com

Loop Through an Indexed Array

<?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 Info@ITBigDig.com

We hope You enjoy This Tutorial.

For any Suggestions Please Email Us

Info@ITBigDig.com

PHP Course Info@ITBigDig.com

EndArrays

top related