PHP Functions and Arrays Overview

PHP Functions and Arrays Overview
Slide Note
Embed
Share

In this lesson, you will delve into the core concepts of PHP functions and arrays. Understand the importance of functions in PHP programming and explore the different types of functions available. Additionally, grasp the basics of arrays and their types in PHP, enhancing your programming skills in web development.

  • PHP programming
  • Functions
  • Arrays
  • Web Development

Uploaded on Feb 27, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Padasalai PHP Function and Array 05 CHAPTER MOHAMED FAKRUDEEN PGT-COMPUTER SCIENCE SHAMROCK MATRIC. HR. SEC. SCHOOL MOGAPPAIR, CHENNAI-107

  2. 2 MOHAMED FAKRUDEEN 2/27/2025 LEARNING OBJECTIVES To understand the importance of Functions concept in PHP To know the types of functions concept in PHP To know the basics of array concepts To know the types of Arrays concept in PHP

  3. 3 MOHAMED FAKRUDEEN 2/27/2025

  4. 4 MOHAMED FAKRUDEEN 2/27/2025 What is Function? In most of the programming language, a block of segment in a program that performs a specific operation tasks such as Insert Execute Delete Calculate etc. This segment is also known as Function.

  5. 5 MOHAMED FAKRUDEEN 2/27/2025 What is Function? (Cont ) A Function is a type of sub routine or procedure in a program. A Function will be executed by a call to the Function and the Function returns any data type values or NULL value to called Function in the part of respective program

  6. 6 MOHAMED FAKRUDEEN 2/27/2025 Types of functions The Function can be divided in to three types as follows User defined Function Pre-defined or System or built-in Function Parameterized Function.

  7. 7 MOHAMED FAKRUDEEN 2/27/2025 User defined Function

  8. 8 MOHAMED FAKRUDEEN 2/27/2025 User Defined Function User Defined Function (UDF) in PHP gives a privilege to user to write own specific operation inside of existing program module. Two important steps the Programmer has to create for users define Functions are: Function Declaration Function Calling

  9. 9 MOHAMED FAKRUDEEN 2/27/2025 Function Declaration A user-defined Function declaration begins with the keyword function . User can write any custom logic inside the function block. Syntax: function functionName() { Custom Logic code to be executed; }

  10. 10 MOHAMED FAKRUDEEN 2/27/2025 Function Calling A function declaration part will be executed by a call to the function. Programmer has to create Function Calling part inside the respective program. Syntax: functionName();

  11. 11 MOHAMED FAKRUDEEN 2/27/2025 Example - Program <?php function insertMsg() { echo Student Details Inserted Successfully! ; } insertMsg(); // call the function ?>

  12. 12 MOHAMED FAKRUDEEN 2/27/2025 Parameterized Function

  13. 13 MOHAMED FAKRUDEEN 2/27/2025 Parameterized Function Required information can be shared between function declaration and function calling part inside the program. The parameter is also called as arguments, it is like variables. The arguments are mentioned after the function name and inside of the parenthesis. There is no limit for sending arguments, just separate them with a comma notation.

  14. 14 MOHAMED FAKRUDEEN 2/27/2025 Example Program 1 The following example has a function with one Argument ($sfname): <?php function School_Name($sname) { echo $sname. in Tamilnadu.<br> ; } School_Name ( Government Higher Secondary School Madurai ); School_Name ( Government Higher Secondary School Trichy ); School_Name ( Government Higher Secondary School Chennai ); School_Name ( Government Higher Secondary School Kanchipuram ); School_Name ( Government Higher Secondary School Tirunelveli ); ?>

  15. 15 MOHAMED FAKRUDEEN 2/27/2025 Example Program 2 The following example has a function with two arguments ($sname and $Strength): <?php function School_Name($sname,$Strength) { echo $sname. in Tamilnadu and Student Strength is .$Strength; } School_Name ( Government Higher Secondary School Madurai ,200); School_Name ( Government Higher Secondary School Trichy ,300); School_Name ( Government Higher Secondary School Chennai ,250); School_Name ( Government Higher Secondary School Kanchipuram ,100); School_Name ( Government Higher Secondary School Tirunelveli ,200); ?>

  16. 16 MOHAMED FAKRUDEEN 2/27/2025 Example - Program3 For a function to return a value, use the return statement <?php function sum($x, $y) { $z = $x + $y; return $z; } echo 5 + 10 = . sum(5, 10) . <br> ; echo 7 + 13 = . sum(7, 13) . <br> ; echo 2 + 4 = . sum(2, 4); ?>

  17. 17 MOHAMED FAKRUDEEN 2/27/2025 ARRAYS IN PHP

  18. 18 MOHAMED FAKRUDEEN 2/27/2025 What are arrays? Array is a concept that stores more than one value of same data type (homogeneous) in single array variable. They are 3 types of array concepts in PHP. Indexed Arrays, Associative Array and Multi-Dimensional Array.

  19. 19 MOHAMED FAKRUDEEN 2/27/2025 Indexed Arrays Arrays with numeric index for the available values in array variable which contains key value pair as user / developer can take the values using keys.

  20. 20 MOHAMED FAKRUDEEN 2/27/2025 Array Syntax: Array defines with the keyword array()

  21. 21 MOHAMED FAKRUDEEN 2/27/2025 Example: <?php $teacher_name=array( Iniyan , Kavin , Nilani ); echo The students name are . $teacher_name[0] . , . $$teacher_name[1] . and . $teacher_name[2] . . ; ?>

  22. 22 MOHAMED FAKRUDEEN 2/27/2025 ASSOCIATIVE ARRAYS Associative arrays are a key-value pair data structure. Instead of having storing data in a linear array, with associative arrays you can store your data in a collection and assign it a unique key which you may use for referencing your data.

  23. 23 MOHAMED FAKRUDEEN 2/27/2025 array(key=>value,key=>value,key=>value,etc.); key = Specifies the key (numeric or string) value = Specifies the value

  24. 24 MOHAMED FAKRUDEEN 2/27/2025 Example: <?php $Marks=array( Student1 => 35 , Student2 => 1 7 , Student3 => 43 ); echo Student1 mark is . $Marks[ Student1 ] . is eligible for qualification ; echo Student2 mark is . $Marks[ Student2 ] . is not eligible for qualification ; ?>

  25. 25 MOHAMED FAKRUDEEN 2/27/2025 Multidimensional Arrays A multidimensional array is an array containing one or more arrays. PHP understands multidimensional arrays that are two, three, four, five, or more levels deep. However, arrays more than three levels deep are hard to manage for most people.

  26. 26 MOHAMED FAKRUDEEN 2/27/2025 <?php// A two-dimensional array $student=array ( array( Iniyan ,100,96), array( Kavin ,60,59), array( Nilani ,1313,139) ); echo $$student[0][0]. : Tamil Mark: .$student [0][1]. . English mark: .$student [0] [2]. <br> ; echo $$student[1][0]. : Tamil Mark: .$student [1][1]. . English mark: .$student [1] [2]. <br> ; echo $$student[2][0]. : Tamil Mark: .$student [2][1]. . English mark: .$student [2] [2]. <br> ; ?>

  27. 27 MOHAMED FAKRUDEEN 2/27/2025 POINTS TO REMEMBER PHP Functions are Reducing duplication of code PHP Functions are Decomposing complex problems into simpler pieces PHP Functions are Improving clarity of the code PHP Functions are Reuse of code PHP Functions are Information hiding PHP arrays are using For each looping concepts

  28. 28 MOHAMED FAKRUDEEN 2/27/2025

More Related Content