arrays php 03
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 LoopTRANSCRIPT
PHP Course3: Arrays
An array stores multiple values in one single variable
PHP Course [email protected]
Instructor Name: Mohamed Saad.
Email: [email protected]
Occupation: Web Developer In IT Big Dig.
PHP Course [email protected]
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]
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 [email protected]
For LoopSyntax
o for (Counter; condition; increment) { code to be executed; }
PHP Course [email protected]
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 [email protected]
We hope You enjoy This Tutorial.
For any Suggestions Please Email Us
PHP Course [email protected]
EndArrays