SlideShare a Scribd company logo
1
Agenda
 Array
 Object
 Null
 Function
An array is a special type of variable that can hold many
values at once, all accessible via a single variable name.
Arrays are very useful whenever you need to work with large
amounts of data — such as records from a database — or
group related data together.
• There are three types of arrays thatyou can create. These are:
• Indexedarray — An array with a numeric key.
• Associative array — An array whereeach key has its own specific value.
• Multidimensional array — An array containing oneor morearrays within
itself.
1. An indexed or numeric array stores each array element with a numeric index. The
following examples shows two ways of creating an indexed array, the easiest way is:
• Note:In an indexedornumericarray,the indexesare automaticallyassignedandstartwith 0,
and the valuescanbe anydata type.
2. In an associative array, the keys assigned to values can be arbitrary
and user defined strings. In the following example the array uses
keys instead of index numbers:
2
3. The multidimensional array is an array in which each element can also be an array and
each element in the sub-array can be an array or further contain array within itself and so
on. An example of a multidimensional array will look something like this:
1. <?php
2. //associative multidimensional array
$mark =array("Abe"=>array( "physics"=>89,"math"=>80,"english"=>90),
"keb"=>array("physics"=>95,"math"=>85,"english"=>95));
3. echo "Abe's physics mark is ". $mark["Abe"]["physics"]."<br>";
4. //indexed multidimensional array
$number = array(array(50,60,70),
array(80,90,40));
5. echo $number[0][0];
6. echo $number[0][1];
7. echo $number[0][2]."<br>";
8. echo $number[1][0];
9. echo $number[1][1];
10. echo $number[1][2]."<br>";
11. echo $number[2][0];
12. echo $number[2][1];
13. echo $number[2][2];
14. ?>
3
4
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Associative
Array</title>
5. </head>
6. <body>
7. <?php
8. $age =
array("Abebe"=>20,
"Kebede"=>14,
"Yohannes"=>45,
"Abay"=>35);
9. asort($age);
10. ?>
11. <table>
12. <tr>
13. <td><?php echo
"Abebe is ".
$age['Abebe']." years
old";?></td>
14. </tr>
15. <tr>
16. <td><?php echo "Sort
by age ascending by
value <br>";?></td>
17. </tr>
18. <tr>
19. <td><?php
print_r($age);?></td>
20. </tr>
21. <tr>
22. <td>
23. Age sort descending
by value
24. </td>
25. </tr>
26. <tr>
27. <td>
28. <?php
29. arsort($age);
30. echo print_r($age);
31. ?>
32. </td>
5
33. </tr>
34. <tr>
35. <td><?php echo "Sort
by age ascending by
key";?></td>
36. </tr>
37. <tr>
38. <td><?php
39. ksort($age);
40. print_r($age);?></td>
41. </tr>
42. <tr>
43. <td>
44. Age sort descending by key
45. </td>
46. </tr>
47. <tr>
48. <td>
49. <?php
50. krsort($age);
51. echo print_r($age);
52. ?>
53. </td>
54. </tr>
55. </table>
56. </body>
57. </html>
6
PHP Function
• A function is a named block of code that is designed to perform a
specific task.
• Once a function is defined, you can reuse it without copying and
pasting a code block again and again.
• A function may accept one or more arguments, which are the
values that you pass to the function.
• A function may return a value so that the calling script can
communicate with it.
Function parameters
• Informationcanbe passedto functionsthrougharguments.Anargumentisjustlike avariable.
• Functionmayaccept one or more parameters.There are twoways to passparameterstoa
function:passingparameterbyvalue andpassingparameterbyreference.
• Parameter iswhat's giveninthe functiondeclaration/definition.
• Argument iswhat'spassedwhencallingthe function.
7
Benefits of using function
• Functions are reusable– Because a function is designed to performa
specific independent task so that it can be reused in other web
applications.
• Functions help avoid duplicate code – A function helps avoid copying
and pasting code all over places by wrapping the logic and assigning it a
name.
• Functions make your scriptmodular – by using functions, a big script is
divided into many functions that are easier to build, test and maintain.
Object
• <?php
• classCar {
• functionCar() {
• $this->model ="VW";
• }
• }
• // create an object
• $herbie = newCar();
• // showobjectproperties
• echo$herbie->model;
• ?>
8
Null
• Null isa special datatype whichcan have onlyone value:NULL.
• A variable of datatype NULL isa variable that has no value assignedtoit.
• If a variable iscreated withoutavalue,itisautomaticallyassignedavalue of NULL.
• Variablescanalsobe emptiedbysettingthe value toNULL:

More Related Content

PPTX
Lesson 11 one dimensional array
PDF
Java arrays (1)
PPTX
Computer programming 2 Lesson 13
PPTX
Data structures and algorithms arrays
PPTX
Java arrays
PPTX
Array in Java
PPTX
PPTX
Arrays accessing using for loops
Lesson 11 one dimensional array
Java arrays (1)
Computer programming 2 Lesson 13
Data structures and algorithms arrays
Java arrays
Array in Java
Arrays accessing using for loops

What's hot (20)

PPTX
Chapter 6 java
PDF
Java Generics wildcards
PPTX
How to Create an Array & types in PHP
PPTX
Array in c#
PPTX
Array in C# 3.5
PPT
Numeric Arrays [6]
PPT
Java collections concept
PPTX
Module 7 : Arrays
PPTX
Dictionaries and Sets in Python
PPTX
Python dictionary
PPTX
Report cs3 pillos
PDF
Java Regular Expression PART I
PPTX
Presentation on array
PDF
PHP Basic & Arrays
PPTX
OOPs with java
PPTX
Array in php
PPTX
An Introduction to Tuple List Dictionary in Python
PPTX
Collections framework in java
PPTX
Mod 12
Chapter 6 java
Java Generics wildcards
How to Create an Array & types in PHP
Array in c#
Array in C# 3.5
Numeric Arrays [6]
Java collections concept
Module 7 : Arrays
Dictionaries and Sets in Python
Python dictionary
Report cs3 pillos
Java Regular Expression PART I
Presentation on array
PHP Basic & Arrays
OOPs with java
Array in php
An Introduction to Tuple List Dictionary in Python
Collections framework in java
Mod 12
Ad

Similar to Array andfunction (20)

PDF
Array String - Web Programming
PPTX
Chapter 2 wbp.pptx
PPTX
PHP Arrays_Introduction
PPTX
Unit 2-Arrays.pptx
PPTX
PHP array 1
PPT
Php my sql - functions - arrays - tutorial - programmerblog.net
PDF
Php array
PPTX
Arrays in php
PPSX
DIWE - Advanced PHP Concepts
PPTX
Introduction to PHP_ Lexical structure_Array_Function_String
PPTX
Web Application Development using PHP Chapter 4
PPTX
Arrays in PHP
PPT
PHP array 2
PPT
Web Technology - PHP Arrays
PPTX
PHP FUNCTIONS AND ARRAY.pptx
PDF
PHP-Part3
PPTX
5 Arry in PHP.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
PDF
4.1 PHP Arrays
PPTX
Chap 3php array part1
PDF
Arrays in PHP
Array String - Web Programming
Chapter 2 wbp.pptx
PHP Arrays_Introduction
Unit 2-Arrays.pptx
PHP array 1
Php my sql - functions - arrays - tutorial - programmerblog.net
Php array
Arrays in php
DIWE - Advanced PHP Concepts
Introduction to PHP_ Lexical structure_Array_Function_String
Web Application Development using PHP Chapter 4
Arrays in PHP
PHP array 2
Web Technology - PHP Arrays
PHP FUNCTIONS AND ARRAY.pptx
PHP-Part3
5 Arry in PHP.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
4.1 PHP Arrays
Chap 3php array part1
Arrays in PHP
Ad

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Electronic commerce courselecture one. Pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Machine learning based COVID-19 study performance prediction
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
MYSQL Presentation for SQL database connectivity
PDF
KodekX | Application Modernization Development
PDF
cuic standard and advanced reporting.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
Teaching material agriculture food technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Chapter 3 Spatial Domain Image Processing.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
Machine learning based COVID-19 study performance prediction
The AUB Centre for AI in Media Proposal.docx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Programs and apps: productivity, graphics, security and other tools
NewMind AI Weekly Chronicles - August'25 Week I
sap open course for s4hana steps from ECC to s4
MYSQL Presentation for SQL database connectivity
KodekX | Application Modernization Development
cuic standard and advanced reporting.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Teaching material agriculture food technology

Array andfunction

  • 1. 1 Agenda  Array  Object  Null  Function An array is a special type of variable that can hold many values at once, all accessible via a single variable name. Arrays are very useful whenever you need to work with large amounts of data — such as records from a database — or group related data together. • There are three types of arrays thatyou can create. These are: • Indexedarray — An array with a numeric key. • Associative array — An array whereeach key has its own specific value. • Multidimensional array — An array containing oneor morearrays within itself. 1. An indexed or numeric array stores each array element with a numeric index. The following examples shows two ways of creating an indexed array, the easiest way is: • Note:In an indexedornumericarray,the indexesare automaticallyassignedandstartwith 0, and the valuescanbe anydata type. 2. In an associative array, the keys assigned to values can be arbitrary and user defined strings. In the following example the array uses keys instead of index numbers:
  • 2. 2 3. The multidimensional array is an array in which each element can also be an array and each element in the sub-array can be an array or further contain array within itself and so on. An example of a multidimensional array will look something like this: 1. <?php 2. //associative multidimensional array $mark =array("Abe"=>array( "physics"=>89,"math"=>80,"english"=>90), "keb"=>array("physics"=>95,"math"=>85,"english"=>95)); 3. echo "Abe's physics mark is ". $mark["Abe"]["physics"]."<br>"; 4. //indexed multidimensional array $number = array(array(50,60,70), array(80,90,40)); 5. echo $number[0][0]; 6. echo $number[0][1]; 7. echo $number[0][2]."<br>"; 8. echo $number[1][0]; 9. echo $number[1][1]; 10. echo $number[1][2]."<br>"; 11. echo $number[2][0]; 12. echo $number[2][1]; 13. echo $number[2][2]; 14. ?>
  • 3. 3
  • 4. 4 1. <!DOCTYPE html> 2. <html> 3. <head> 4. <title>Associative Array</title> 5. </head> 6. <body> 7. <?php 8. $age = array("Abebe"=>20, "Kebede"=>14, "Yohannes"=>45, "Abay"=>35); 9. asort($age); 10. ?> 11. <table> 12. <tr> 13. <td><?php echo "Abebe is ". $age['Abebe']." years old";?></td> 14. </tr> 15. <tr> 16. <td><?php echo "Sort by age ascending by value <br>";?></td> 17. </tr> 18. <tr> 19. <td><?php print_r($age);?></td> 20. </tr> 21. <tr> 22. <td> 23. Age sort descending by value 24. </td> 25. </tr> 26. <tr> 27. <td> 28. <?php 29. arsort($age); 30. echo print_r($age); 31. ?> 32. </td>
  • 5. 5 33. </tr> 34. <tr> 35. <td><?php echo "Sort by age ascending by key";?></td> 36. </tr> 37. <tr> 38. <td><?php 39. ksort($age); 40. print_r($age);?></td> 41. </tr> 42. <tr> 43. <td> 44. Age sort descending by key 45. </td> 46. </tr> 47. <tr> 48. <td> 49. <?php 50. krsort($age); 51. echo print_r($age); 52. ?> 53. </td> 54. </tr> 55. </table> 56. </body> 57. </html>
  • 6. 6 PHP Function • A function is a named block of code that is designed to perform a specific task. • Once a function is defined, you can reuse it without copying and pasting a code block again and again. • A function may accept one or more arguments, which are the values that you pass to the function. • A function may return a value so that the calling script can communicate with it. Function parameters • Informationcanbe passedto functionsthrougharguments.Anargumentisjustlike avariable. • Functionmayaccept one or more parameters.There are twoways to passparameterstoa function:passingparameterbyvalue andpassingparameterbyreference. • Parameter iswhat's giveninthe functiondeclaration/definition. • Argument iswhat'spassedwhencallingthe function.
  • 7. 7 Benefits of using function • Functions are reusable– Because a function is designed to performa specific independent task so that it can be reused in other web applications. • Functions help avoid duplicate code – A function helps avoid copying and pasting code all over places by wrapping the logic and assigning it a name. • Functions make your scriptmodular – by using functions, a big script is divided into many functions that are easier to build, test and maintain. Object • <?php • classCar { • functionCar() { • $this->model ="VW"; • } • } • // create an object • $herbie = newCar(); • // showobjectproperties • echo$herbie->model; • ?>
  • 8. 8 Null • Null isa special datatype whichcan have onlyone value:NULL. • A variable of datatype NULL isa variable that has no value assignedtoit. • If a variable iscreated withoutavalue,itisautomaticallyassignedavalue of NULL. • Variablescanalsobe emptiedbysettingthe value toNULL: