Arrays PHP 03

667 views

Published on

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

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
667
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
55
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Arrays PHP 03

  1. 1. PHP Course 3: Arrays An array stores multiple values in one single variable PHP Course Info@ITBigDig.com
  2. 2. Instructor  Name: Mohamed Saad.  Email: Engsaad_aly@hotmail.com  Occupation: Web Developer In IT Big Dig. PHP Course Info@ITBigDig.com
  3. 3. 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
  4. 4. 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.
  5. 5. PHP Array • There are three types of arrays: •Arrays with numeric indexIndexed arrays •Arrays with named keysAssociative arrays •Arrays containing one or more arraysMultidimensional arrays
  6. 6. array() Function Syntax •array(‘value’, );indexed •array(‘key’ =>’value’, );associative
  7. 7. count() Function Syntax o $x=array("Volvo“,"BMW“,"Toyota"); echo count($x);
  8. 8. sort() Function
  9. 9. <?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 Code array1.php PHP Course Info@ITBigDig.com
  10. 10. For Loop Syntax o for (Counter; condition; increment) { code to be executed; } PHP Course Info@ITBigDig.com
  11. 11. Loop Through an Indexed Array
  12. 12. <?php $cars=array("Volvo","BMW","Toyota"); $arrlength=count($cars); echo $arrlength,"<br>"; for($x=0;$x<$arrlength;$x++) { echo $cars[$x]; echo "<br>"; } ?> Copy Code for.php PHP Course Info@ITBigDig.com
  13. 13. We hope You enjoy This Tutorial. For any Suggestions Please Email Us Info@ITBigDig.com PHP Course Info@ITBigDig.com End Arrays

×