محاضرة 3
PHP Loops and Functions
الحلقات التكرارية والدوال في PHP.
يلا نشوف الملخص
Lecture 3: Continue Fundamentals of PHP (Loops and Functions)
Overview: This lecture dives into control flow through iterative loops and creating modular code using PHP functions.
- PHP Loops:
- while loop: Executes a block of code as long as a specified condition is true.
- do...while loop: Executes the block of code once before checking the condition, then repeats as long as the condition remains true.
- for loop: Loops through a block of code a specified number of times.
- foreach loop: Specifically used to loop through each element (keys and values) in an array.
- Loop Control Statements:
- break: Stops the loop completely and jumps out.
- continue: Skips the current iteration and jumps immediately to the next iteration.
- PHP Functions:
- Creation: Declared using the
functionkeyword (e.g.,function myMessage() { }). - Calling: Executed by calling the function's name followed by parentheses.
- Arguments: Data passed into the function to be processed.
- Default Argument Value: If an argument is declared with a default (e.g.,
$minheight = 50), calling the function without an argument will automatically use the default value. - Returning Values: The
returnstatement is used to send a computed value back to the caller.
- Creation: Declared using the
في نقطة مش واضحة؟ بطبط موجود!
اسأل بطبط عنها