PHP and Algorithmic Thinking for the Complete Beginner

Book description

Dive into the world of PHP programming and algorithmic thinking with this comprehensive course designed for beginners. Learn the essentials of PHP and build a strong foundation in algorithmic concepts.

Key Features

  • Understand how computers work and the basics of programming
  • Learn to use PHP and IDEs, and master variables, constants, operators, and control structures
  • Develop skills in manipulating data structures, while learning how to create and use subprograms

Book Description

Begin your journey into PHP programming and algorithmic thinking with a structured, detailed course that takes you from understanding the basic components of a computer to mastering complex decision control and loop structures. Each chapter builds on the previous one, starting with an introduction to how computers work and gradually progressing to more complex topics like decision control structures, loop structures, arrays, and subprograms.

You'll start with foundational concepts such as variables, constants, and operators, before diving into more advanced topics like manipulating strings, handling input and output, and developing complex mathematical expressions. The course emphasizes practical application, guiding you through the use of Visual Studio Code, integrated development environments, and essential software packages.

By the end of this book, you will have a solid understanding of PHP programming and algorithmic thinking, enabling you to write efficient code, develop your own subprograms, and utilize various control structures and arrays effectively. This course is tailored for beginners, ensuring a smooth learning curve with tips, tricks, and exercises to reinforce your knowledge, and prepare you with the necessary skills needed to be a programmer.

What you will learn

  • Utilize PHP for various programming tasks
  • Implement control structures, loops, and arrays in code
  • Develop and use subprograms for modular programming
  • Apply object-oriented principles and manage files in PHP
  • Analyze and debug PHP code effectively
  • Integrate PHP with databases for dynamic web development

Who this book is for

This course is ideal for complete beginners with no prior programming experience. It is also perfect for students, self-taught programmers, and professionals looking to refresh their knowledge of PHP and algorithmic thinking. Educators seeking to enhance their teaching methods and hobbyists wanting to explore programming as a new skill will also benefit greatly. Basic computer literacy is recommended, but no specific prerequisites are required.

Table of contents

  1. Table of Contents
  2. Preface
    1. About the Author
    2. Acknowledgments
    3. How This Book is Organized
    4. Who Should Buy This Book?
    5. Conventions Used in This Book
    6. How to Report Errata
    7. Where to Download Material About this Book
    8. If you Like this Book
  3. Part I Introductory Knowledge
    1. Chapter 1 How a Computer Works
      1. 1.1 Introduction
      2. 1.2 What is Hardware?
      3. 1.3 What is Software?
      4. 1.4 How a Computer Executes (Runs) a Program
      5. 1.5 Compilers and Interpreters
      6. 1.6 What is Source Code?
      7. 1.7 Review Questions: True/False
      8. 1.8 Review Questions: Multiple Choice
    2. Chapter 2 PHP and Integrated Development Environments
      1. 2.1 What is PHP?
      2. 2.2 What is the Difference Between a Script and a Program?
      3. 2.3 Why You Should Learn PHP
      4. 2.4 How PHP Works
      5. 2.5 Integrated Development Environments
      6. 2.6 Visual Studio
    3. Chapter 3 Software Packages to Install
      1. 3.1 What to Install
    4. Review in “Introductory Knowledge”
      1. Review Crossword Puzzles
      2. Review Questions
  4. Part II Getting Started with PHP
    1. Chapter 4 Introduction to Basic Algorithmic Concepts
      1. 4.1 What is an Algorithm?
      2. 4.2 The Algorithm for Making a Cup of Tea
      3. 4.3 Properties of an Algorithm
      4. 4.4 Okay About Algorithms. But What is a Computer Program Anyway?
      5. 4.5 The Three Parties!
      6. 4.6 The Three Main Stages Involved in Creating an Algorithm
      7. 4.7 Flowcharts
        1. Exercise 4.7-1 Finding the Average Value of Three Numbers
      8. 4.8 What are ”Reserved Words”?
      9. 4.9 What is the Difference Between a Statement and a Command?
      10. 4.10 What is Structured Programming?
      11. 4.11 The Three Fundamental Control Structures
        1. Exercise 4.11-1 Understanding Control Structures Using Flowcharts
      12. 4.12 Your First PHP Script
      13. 4.13 What is the Difference Between a Syntax Error, a Logic Error, and a Runtime Error?
      14. 4.14 What “Debugging” Means
      15. 4.15 Commenting Your Code
      16. 4.16 User-Friendly Programs and Scripts
      17. 4.17 Review Questions: True/False
      18. 4.18 Review Questions: Multiple Choice
    2. Chapter 5 Variables and Constants
      1. 5.1 What is a Variable?
      2. 5.2 What is a Constant?
      3. 5.3 How Many Types of Variables and Constants Exist?
      4. 5.4 Rules and Conventions for Naming Variables and Constants in PHP
      5. 5.5 What Does the Phrase “Declare a Variable” Mean?
      6. 5.6 How to Declare Variables in PHP
      7. 5.7 How to Declare Constants in PHP
      8. 5.8 Review Questions: True/False
      9. 5.9 Review Questions: Multiple Choice
      10. 5.10 Review Exercises
    3. Chapter 6 Handling Input and Output
      1. 6.1 How to Output Messages and Results to a User's Screen?
      2. 6.2 How to Output Special Characters?
      3. 6.3 How to Prompt the User to Enter Data?
      4. 6.4 Review Questions: True/False
      5. 6.5 Review Questions: Multiple Choice
    4. Chapter 7 Operators
      1. 7.1 The Value Assignment Operator
      2. 7.2 Arithmetic Operators
      3. 7.3 What is the Precedence of Arithmetic Operators?
      4. 7.4 Compound Assignment Operators
        1. Exercise 7.4-1 Which PHP Statements are Syntactically Correct?
        2. Exercise 7.4-2 Finding Variable Types
      5. 7.5 Incrementing/Decrementing Operators
      6. 7.6 String Operators
        1. Exercise 7.6-1 Concatenating Names
      7. 7.7 Review Questions: True/False
      8. 7.8 Review Questions: Multiple Choice
      9. 7.9 Review Exercises
    5. Chapter 8 Trace Tables
      1. 8.1 What is a Trace Table?
        1. Exercise 8.1-1 Creating a Trace Table
        2. Exercise 8.1-2 Creating a Trace Table
        3. Exercise 8.1-3 Swapping Values of Variables
        4. Exercise 8.1-4 Swapping Values of Variables – An Alternative Approach
      2. 8.2 Review Questions: True/False
      3. 8.3 Review Exercises
    6. Chapter 9 Using Visual Studio Code
      1. 9.1 Write, Execute and Debug PHP Scripts
    7. Review in “Getting Started with PHP”
      1. Review Crossword Puzzles
      2. Review Questions
  5. Part III Sequence Control Structures
    1. Chapter 10 Introduction to Sequence Control Structures
      1. 10.1 What is the Sequence Control Structure?
        1. Exercise 10.1-1 Calculating the Area of a Rectangle
        2. Exercise 10.1-2 Calculating the Area of a Circle
        3. Exercise 10.1-3 Where is the Car? Calculating Distance Traveled
        4. Exercise 10.1-4 Kelvin to Fahrenheit
        5. Exercise 10.1-5 Calculating Sales Tax
        6. Exercise 10.1-6 Calculating a Sales Discount
        7. Exercise 10.1-7 Calculating a Sales Discount and Tax
      2. 10.2 Review Exercises
    2. Chapter 11 Manipulating Numbers
      1. 11.1 Introduction
      2. 11.2 Useful Mathematical Functions (Subprograms), and More
        1. Exercise 11.2-1 Calculating the Distance Between Two Points
        2. Exercise 11.2-2 How Far Did the Car Travel?
      3. 11.3 Review Questions: True/False
      4. 11.4 Review Questions: Multiple Choice
      5. 11.5 Review Exercises
    3. Chapter 12 Complex Mathematical Expressions
      1. 12.1 Writing Complex Mathematical Expressions
        1. Exercise 12.1-1 Representing Mathematical Expressions in PHP
        2. Exercise 12.1-2 Writing a Mathematical Expression in PHP
        3. Exercise 12.1-3 Writing a Complex Mathematical Expression in PHP
      2. 12.2 Review Exercises
    4. Chapter 13 Exercises With a Quotient and a Remainder
      1. 13.1 Introduction
        1. Exercise 13.1-1 Calculating the Quotient and Remainder of Integer Division
        2. Exercise 13.1-2 Finding the Sum of Digits
        3. Exercise 13.1-3 Displaying an Elapsed Time
        4. Exercise 13.1-4 Reversing a Number
      2. 13.2 Review Exercises
    5. Chapter 14 Manipulating Strings
      1. 14.1 Introduction
      2. 14.2 The Position of a Character in a String
      3. 14.3 Useful String Functions (Subprograms), and More
        1. Exercise 14.3-1 Displaying a String Backwards
        2. Exercise 14.3-2 Switching the Order of Names
        3. Exercise 14.3-3 Creating a Login ID
        4. Exercise 14.3-4 Creating a Random Word
        5. Exercise 14.3-5 Finding the Sum of Digits
      4. 14.4 Review Questions: True/False
      5. 14.5 Review Questions: Multiple Choice
      6. 14.6 Review Exercises
    6. Review in “Sequence Control Structures”
      1. Review Crossword Puzzle
      2. Review Questions
  6. Part IV Decision Control Structures
    1. Chapter 15 Making Questions
      1. 15.1 Introduction
      2. 15.2 What is a Boolean Expression?
      3. 15.3 How to Write Simple Boolean Expressions
        1. Exercise 15.3-1 Filling in the Table
      4. 15.4 Logical Operators and Complex Boolean Expressions
        1. Exercise 15.4-1 Calculating the Results of Complex Boolean Expressions
      5. 15.5 Assigning the Result of a Boolean Expression to a Variable
      6. 15.6 What is the Order of Precedence of Logical Operators?
        1. Exercise 15.6-1 Filling in the Truth Table
        2. Exercise 15.6-2 Converting English Sentences to Boolean Expressions
      7. 15.7 What is the Order of Precedence of Arithmetic, Comparison, and Logical Operators?
      8. 15.8 How to Negate Boolean Expressions
        1. Exercise 15.8-1 Negating Boolean Expressions
      9. 15.9 Review Questions: True/False
      10. 15.10 Review Questions: Multiple Choice
      11. 15.11 Review Exercises
    2. Chapter 16 The Single-Alternative Decision Structure
      1. 16.1 The Single-Alternative Decision Structure
        1. Exercise 16.1-1 Trace Tables and Single-Alternative Decision Structures
        2. Exercise 16.1-2 The Absolute Value of a Number
      2. 16.2 Review Questions: True/False
      3. 16.3 Review Questions: Multiple Choice
      4. 16.4 Review Exercises
    3. Chapter 17 The Dual-Alternative Decision Structure
      1. 17.1 The Dual-Alternative Decision Structure
        1. Exercise 17.1-1 Finding the Output Message
        2. Exercise 17.1-2 Trace Tables and Dual-Alternative Decision Structures
        3. Exercise 17.1-3 Who is the Greatest?
        4. Exercise 17.1-4 Finding Odd and Even Numbers
        5. Exercise 17.1-5 Weekly Wages
      2. 17.2 Review Questions: True/False
      3. 17.3 Review Questions: Multiple Choice
      4. 17.4 Review Exercises
    4. Chapter 18 The Multiple-Alternative Decision Structure
      1. 18.1 The Multiple-Alternative Decision Structure
        1. Exercise 18.1-1 Trace Tables and Multiple-Alternative Decision Structures
        2. Exercise 18.1-2 Counting the Digits
      2. 18.2 Review Questions: True/False
      3. 18.3 Review Exercises
    5. Chapter 19 The Case Decision Structure
      1. 19.1 The Case Decision Structure
        1. Exercise 19.1-1 The Days of the Week
      2. 19.2 Review Questions: True/False
      3. 19.3 Review Exercises
    6. Chapter 20 Nested Decision Control Structures
      1. 20.1 What are Nested Decision Control Structures?
        1. Exercise 20.1-1 Trace Tables and Nested Decision Control Structures
        2. Exercise 20.1-2 Positive, Negative or Zero?
      2. 20.2 Review Questions: True/False
      3. 20.3 Review Exercises
    7. Chapter 21 More about Flowcharts with Decision Control Structures
      1. 21.1 Introduction
      2. 21.2 Converting PHP scripts to Flowcharts
        1. Exercise 21.2-1 Designing the Flowchart
        2. Exercise 21.2-2 Designing the Flowchart
        3. Exercise 21.2-3 Designing the Flowchart
      3. 21.3 A Mistake That You Will Probably Make!
      4. 21.4 Converting Flowcharts to PHP scripts
        1. Exercise 21.4-1 Writing the PHP Script
        2. Exercise 21.4-2 Writing the PHP Script
        3. Exercise 21.4-3 Writing the PHP Script
      5. 21.5 Review Exercises
    8. Chapter 22 Tips and Tricks with Decision Control Structures
      1. 22.1 Introduction
      2. 22.2 Choosing a Decision Control Structure
      3. 22.3 Streamlining the Decision Control Structure
        1. Exercise 22.3-1 “Shrinking” the Algorithm
        2. Exercise 22.3-2 “Shrinking” the PHP script
        3. Exercise 22.3-3 “Shrinking” the Algorithm
      4. 22.4 Logical Operators – to Use, or not to Use: That is the Question!
        1. Exercise 22.4-1 Rewriting the Code
        2. Exercise 22.4-2 Rewriting the Code
      5. 22.5 Merging Two or More Single-Alternative Decision Structures
        1. Exercise 22.5-1 Merging the Decision Control Structures
        2. Exercise 22.5-2 Merging the Decision Control Structures
      6. 22.6 Replacing Two Single-Alternative Decision Structures with a Dual-Alternative One
        1. Exercise 22.6-1 “Merging” the Decision Control Structures
      7. 22.7 Put the Boolean Expressions Most Likely to be True First
        1. Exercise 22.7-1 Rearranging the Boolean Expressions
      8. 22.8 Why is Code Indentation so Important?
      9. 22.9 Review Questions: True/False
      10. 22.10 Review Questions: Multiple Choice
      11. 22.11 Review Exercises
    9. Chapter 23 More with Decision Control Structures
      1. 23.1 Simple Exercises with Decision Control Structures
        1. Exercise 23.1-1 Is it an Integer?
        2. Exercise 23.1-2 Validating Data Input and Finding Odd and Even Numbers
        3. Exercise 23.1-3 Where is the Tollkeeper?
        4. Exercise 23.1-4 The Most Scientific Calculator Ever!
        5. Exercise 23.1-5 Converting Gallons to Liters, and Vice Versa
        6. Exercise 23.1-6 Converting Gallons to Liters, and Vice Versa (with Data Validation)
      2. 23.2 Finding Minimum and Maximum Values with Decision Control Structures
        1. Exercise 23.2-1 Finding the Name of the Heaviest Person
      3. 23.3 Decision Control Structures in Solving Mathematical Problems
        1. Exercise 23.3-1 Finding the Value of y
        2. Exercise 23.3-2 Finding the Values of y
        3. Exercise 23.3-3 Solving the Linear Equation ax + b = 0
        4. Exercise 23.3-4 Solving the Quadratic Equation ax2 + bx + c = 0
      4. 23.4 Exercises with Series of Consecutive Ranges of Values
        1. Exercise 23.4-1 Calculating the Discount
        2. Exercise 23.4-2 Validating Data Input and Calculating the Discount
        3. Exercise 23.4-3 Sending a Parcel
        4. Exercise 23.4-4 Finding the Values of y
        5. Exercise 23.4-5 Progressive Rates and Electricity Consumption
        6. Exercise 23.4-6 Progressive Rates and Text Messaging Services
      5. 23.5 Exercises of a General Nature with Decision Control Structures
        1. Exercise 23.5-1 Finding a Leap Year
        2. Exercise 23.5-2 Displaying the Days of the Month
        3. Exercise 23.5-3 Checking for Proper Capitalization and Punctuation
        4. Exercise 23.5-4 Is the Number a Palindrome?
      6. 23.6 Boolean Expressions Reference and Handy Tips
      7. 23.7 Review Exercises
    10. Review in “Decision Control Structures”
      1. Review Crossword Puzzle
      2. Review Questions
  7. Part V Loop Control Structures
    1. Chapter 24 Introduction to Loop Control Structures
      1. 24.1 What is a Loop Control Structure?
      2. 24.2 From Sequence Control to Loop Control Structures
      3. 24.3 Review Questions: True/False
    2. Chapter 25 Pre-Test, Mid-Test and Post-Test Loop Structures
      1. 25.1 The Pre-Test Loop Structure
        1. Exercise 25.1-1 Designing the Flowchart and Counting the Total Number of Iterations
        2. Exercise 25.1-2 Counting the Total Number of Iterations
        3. Exercise 25.1-3 Counting the Total Number of Iterations
        4. Exercise 25.1-4 Counting the Total Number of Iterations
        5. Exercise 25.1-5 Finding the Sum of Four Numbers
        6. Exercise 25.1-6 Finding the Sum of Odd Numbers
        7. Exercise 25.1-7 Finding the Sum of N Numbers
        8. Exercise 25.1-8 Finding the Sum of an Unknown Quantity of Numbers
        9. Exercise 25.1-9 Finding the Product of 20 Numbers
      2. 25.2 The Post-Test Loop Structure
        1. Exercise 25.2-1 Designing the Flowchart and Counting the Total Number of Iterations
        2. Exercise 25.2-2 Counting the Total Number of Iterations
        3. Exercise 25.2-3 Designing the Flowchart and Counting the Total Number of Iterations
        4. Exercise 25.2-4 Counting the Total Number of Iterations
        5. Exercise 25.2-5 Finding the Product of N Numbers
      3. 25.3 The Mid-Test Loop Structure
        1. Exercise 25.3-1 Designing the Flowchart and Counting the Total Number of Iterations
      4. 25.4 Review Questions: True/False
      5. 25.5 Review Questions: Multiple Choice
      6. 25.6 Review Exercises
    3. Chapter 26 Definite Loops
      1. 26.1 The for statement
        1. Exercise 26.1-1 Creating the Trace Table
        2. Exercise 26.1-2 Creating the Trace Table
        3. Exercise 26.1-3 Counting the Total Number of Iterations
        4. Exercise 26.1-4 Finding the Sum of Four Numbers
        5. Exercise 26.1-5 Finding the Square Roots from 0 to N
        6. Exercise 26.1-6 Finding the Sum of 1 + 2 + 3 + … + 100
        7. Exercise 26.1-7 Finding the Product of 2 × 4 × 6 × 8 × 10
        8. Exercise 26.1-8 Finding the Sum of 22 + 42 + 62 + … (2N)2
        9. Exercise 26.1-9 Finding the Sum of 33 + 66 + 99 + … (3N)3N
        10. Exercise 26.1-10 Finding the Average Value of Positive Numbers
        11. Exercise 26.1-11 Counting the Vowels
      2. 26.2 Rules that Apply to For-Loops
        1. Exercise 26.2-1 Counting the Total Number of Iterations
        2. Exercise 26.2-2 Counting the Total Number of Iterations
        3. Exercise 26.2-3 Counting the Total Number of Iterations
        4. Exercise 26.2-4 Counting the Total Number of Iterations
        5. Exercise 26.2-5 Finding the Sum of N Numbers
      3. 26.3 Review Questions: True/False
      4. 26.4 Review Questions: Multiple Choice
      5. 26.5 Review Exercises
    4. Chapter 27 Nested Loop Control Structures
      1. 27.1 What is a Nested Loop?
        1. Exercise 27.1-1 Say “Hello Zeus”. Counting the Total Number of Iterations.
        2. Exercise 27.1-2 Creating the Trace Table
      2. 27.2 Rules that Apply to Nested Loops
        1. Exercise 27.2-1 Violating the First Rule
        2. Exercise 27.2-2 Violating the Second Rule
      3. 27.3 Review Questions: True/False
      4. 27.4 Review Questions: Multiple Choice
      5. 27.5 Review Exercises
    5. Chapter 28 More about Flowcharts with Loop Control Structures
      1. 28.1 Introduction
      2. 28.2 Converting PHP scripts to Flowcharts
        1. Exercise 28.2-1 Designing the Flowchart Fragment
        2. Exercise 28.2-2 Designing the Flowchart Fragment
        3. Exercise 28.2-3 Designing the Flowchart
        4. Exercise 28.2-4 Designing the Flowchart Fragment
        5. Exercise 28.2-5 Designing the Flowchart
      3. 28.3 Converting Flowcharts to PHP scripts
        1. Exercise 28.3-1 Writing the PHP Script
        2. Exercise 28.3-2 Writing the PHP Script
        3. Exercise 28.3-3 Writing the PHP Script
        4. Exercise 28.3-4 Writing the PHP Script
      4. 28.4 Review Exercises
    6. Chapter 29 Tips and Tricks with Loop Control Structures
      1. 29.1 Introduction
      2. 29.2 Choosing a Loop Control Structure
      3. 29.3 The “Ultimate” Rule
      4. 29.4 Breaking Out of a Loop
      5. 29.5 Cleaning Out Your Loops
        1. Exercise 29.5-1 Cleaning Out the Loop
        2. Exercise 29.5-2 Cleaning Out the Loop
      6. 29.6 Endless Loops and How to Stop Them
      7. 29.7 The “From Inner to Outer” Method
      8. 29.8 Review Questions: True/False
      9. 29.9 Review Questions: Multiple Choice
      10. 29.10 Review Exercises
    7. Chapter 30 More with Loop Control Structures
      1. 30.1 Simple Exercises with Loop Control Structures
        1. Exercise 30.1-1 Counting the Numbers According to Which is Greater
        2. Exercise 30.1-2 Counting the Numbers According to Their Digits
        3. Exercise 30.1-3 How Many Numbers Fit in a Sum
        4. Exercise 30.1-4 Finding the Total Number of Positive Integers
        5. Exercise 30.1-5 Iterating as Many Times as the User Wishes
        6. Exercise 30.1-6 Finding the Sum of the Digits
      2. 30.2 Exercises with Nested Loop Control Structures
        1. Exercise 30.2-1 Displaying all Three-Digit Integers that Contain a Given Digit
        2. Exercise 30.2-2 Displaying all Instances of a Specified Condition
      3. 30.3 Data Validation with Loop Control Structures
        1. Exercise 30.3-1 Finding Odd and Even Numbers - Validation Without Error Messages
        2. Exercise 30.3-2 Finding the Sum of Four Numbers
      4. 30.4 Finding Minimum and Maximum Values with Loop Control Structures
        1. Exercise 30.4-1 Validating and Finding the Minimum and the Maximum Value
        2. Exercise 30.4-2 Validating and Finding the Hottest Planet
        3. Exercise 30.4-3 ”Making the Grade”
      5. 30.5 Using Loop Control Structures to Solve Mathematical Problems
        1. Exercise 30.5-1 Calculating the Area of as Many Triangles as the User Wishes
        2. Exercise 30.5-2 Finding x and y
        3. Exercise 30.5-3 The Russian Multiplication Algorithm
        4. Exercise 30.5-4 Finding the Number of Divisors
        5. Exercise 30.5-5 Is the Number a Prime?
        6. Exercise 30.5-6 Finding all Prime Numbers from 1 to N
        7. Exercise 30.5-7 Heron's Square Root
        8. Exercise 30.5-8 Calculating π
        9. Exercise 30.5-9 Approximating a Real with a Fraction
      6. 30.6 Exercises of a General Nature with Loop Control Structures
        1. Exercise 30.6-1 Fahrenheit to Kelvin, from 0 to 100
        2. Exercise 30.6-2 Rice on a Chessboard
        3. Exercise 30.6-3 Just a Poll
        4. Exercise 30.6-4 Is the Message a Palindrome?
      7. 30.7 Review Questions: True/False
      8. 30.8 Review Exercises
    8. Review in “Loop Control Structures”
      1. Review Crossword Puzzle
      2. Review Questions
  8. Part VI Arrays in PHP
    1. Chapter 31 One-Dimensional Arrays
      1. 31.1 Introduction
      2. 31.2 What is an Array?
        1. Exercise 31.2-1 Designing an Array
        2. Exercise 31.2-2 Designing Arrays
        3. Exercise 31.2-3 Designing Arrays
      3. 31.3 Creating One-Dimensional Arrays in PHP
      4. 31.4 How to Get Values from a One-Dimensional Array
        1. Exercise 31.4-1 Creating the Trace Table
        2. Exercise 31.4-2 Using a Non-Existing Index
      5. 31.5 How to Alter the Value of an Array Element
      6. 31.6 How to Iterate Through a One-Dimensional Array
        1. Exercise 31.6-1 Finding the Sum
      7. 31.7 How to Add User-Entered Values to a One-Dimensional Array
        1. Exercise 31.7-1 Displaying Words in Reverse Order
        2. Exercise 31.7-2 Displaying Positive Numbers in Reverse Order
        3. Exercise 31.7-3 Finding the Average Value
        4. Exercise 31.7-4 Displaying Reals Only
        5. Exercise 31.7-5 Displaying Elements with Odd-Numbered Indexes
        6. Exercise 31.7-6 Displaying Even Numbers in Odd–Numbered Index Positions
      8. 31.8 What is an Map?
      9. 31.9 Creating Associative Arrays in PHP
      10. 31.10 How to Get a Value from an Associative Array
        1. Exercise 31.10-1 Roman Numerals to Numbers
        2. Exercise 31.10-2 Using a Non-Existing Key in Dictionaries
      11. 31.11 How to Alter the Value of an Element of an Associative Array
      12. 31.12 How to Iterate Through an Associative Array
      13. 31.13 Review Questions: True/False
      14. 31.14 Review Questions: Multiple Choice
      15. 31.15 Review Exercises
    2. Chapter 32 Two-Dimensional Arrays
      1. 32.1 Creating Two-Dimensional Arrays in PHP
      2. 32.2 How to Get Values from Two-Dimensional Arrays
        1. Exercise 32.2-1 Creating the Trace Table
      3. 32.3 How to Iterate Through a Two-Dimensional Array
      4. 32.4 How to Add User-Entered Values to a Two-Dimensional Array
        1. Exercise 32.4-1 Displaying Reals Only
        2. Exercise 32.4-2 Displaying Odd Columns Only
      5. 32.5 What's the Story on Variables $i and $j?
      6. 32.6 Square Matrices
        1. Exercise 32.6-1 Finding the Sum of the Elements on the Main Diagonal
        2. Exercise 32.6-2 Finding the Sum of the Elements on the Antidiagonal
        3. Exercise 32.6-3 Filling in the Array
      7. 32.7 Review Questions: True/False
      8. 32.8 Review Questions: Multiple Choice
      9. 32.9 Review Exercises
    3. Chapter 33 Tips and Tricks with Arrays
      1. 33.1 Introduction
      2. 33.2 Processing Each Row Individually
        1. Exercise 33.2-1 Finding the Average Value
      3. 33.3 Processing Each Column Individually
        1. Exercise 33.3-1 Finding the Average Value
      4. 33.4 How to Use More Than One Arrays in a Script
        1. Exercise 33.4-1 Using Three One-Dimensional Arrays
        2. Exercise 33.4-2 Using a One-Dimensional Array Along with a Two-Dimensional Array
        3. Exercise 33.4-3 Using an Indexed Array Along with an Associative Array
      5. 33.5 Creating a One-Dimensional Array from a Two-Dimensional Array
      6. 33.6 Creating a Two-Dimensional Array from a One-Dimensional Array
      7. 33.7 Useful Array Functions (Subprograms)
      8. 33.8 Review Questions: True/False
      9. 33.9 Review Questions: Multiple Choice
      10. 33.10 Review Exercises
    4. Chapter 34 More with Arrays
      1. 34.1 Simple Exercises with Arrays
        1. Exercise 34.1-1 Creating an Array that Contains the Average Values of its Neighboring Elements
        2. Exercise 34.1-2 Creating an Array with the Greatest Values
        3. Exercise 34.1-3 Merging One-Dimensional Arrays
        4. Exercise 34.1-4 Creating Two Arrays – Separating Positive from Negative Values
        5. Exercise 34.1-5 Creating an Array with Those who Contain Digit 5
      2. 34.2 Data Validation with Arrays
        1. Exercise 34.2-1 Displaying Odds in Reverse Order
      3. 34.3 Finding Minimum and Maximum Values in Arrays
        1. Exercise 34.3-1 Which Depth is the Greatest?
        2. Exercise 34.3-2 Which Lake is the Deepest?
        3. Exercise 34.3-3 Which Lake, in Which Country, Having Which Average Area, is the Deepest?
        4. Exercise 34.3-4 Which Students Have got the Greatest Grade?
        5. Exercise 34.3-5 Finding the Minimum Value of a Two-Dimensional Array
        6. Exercise 34.3-6 Finding the City with the Coldest Day
        7. Exercise 34.3-7 Finding the Minimum and the Maximum Value of Each Row
      4. 34.4 Sorting Arrays
        1. Exercise 34.4-1 The Bubble Sort Algorithm – Sorting One-Dimensional Arrays with Numeric Values
        2. Exercise 34.4-2 Sorting One-Dimensional Arrays with Alphanumeric Values
        3. Exercise 34.4-3 Sorting One-Dimensional Arrays While Preserving the Relationship with a Second Array
        4. Exercise 34.4-4 Sorting Last and First Names
        5. Exercise 34.4-5 Sorting a Two-Dimensional Array
        6. Exercise 34.4-6 The Modified Bubble Sort Algorithm – Sorting One-Dimensional Arrays
        7. Exercise 34.4-7 The Selection Sort Algorithm – Sorting One-Dimensional Arrays
        8. Exercise 34.4-8 Sorting One-Dimensional Arrays While Preserving the Relationship with a Second Array
        9. Exercise 34.4-9 The Insertion Sort Algorithm – Sorting One-Dimensional Arrays
        10. Exercise 34.4-10 The Three Worst Elapsed Times
      5. 34.5 Searching Elements in Arrays
        1. Exercise 34.5-1 The Linear Search Algorithm – Searching in a One-Dimensional Array that may Contain the Same Value Multiple Times
        2. Exercise 34.5-2 Display the Last Names of All Those People Who Have the Same First Name
        3. Exercise 34.5-3 The Linear Search Algorithm – Searching in a Two-Dimensional Array that May Contain the Same Value Multiple Times
        4. Exercise 34.5-4 The Linear Search Algorithm – Searching in a One-Dimensional Array that Contains Unique Values
        5. Exercise 34.5-5 Searching for a Social Security Number
        6. Exercise 34.5-6 The Linear Search Algorithm – Searching in a Two-Dimensional Array that Contains Unique Values
        7. Exercise 34.5-7 Checking if a Value Exists in all Columns
        8. Exercise 34.5-8 The Binary Search Algorithm – Searching in a Sorted One-Dimensional Array
        9. Exercise 34.5-9 Display all the Historical Events for a Country
        10. Exercise 34.5-10 Searching in Each Column of a Two-Dimensional Array
      6. 34.6 Exercises of a General Nature with Arrays
        1. Exercise 34.6-1 On Which Days was There a Possibility of Snow?
        2. Exercise 34.6-2 Was There Any Possibility of Snow?
        3. Exercise 34.6-3 In Which Cities was There a Possibility of Snow?
        4. Exercise 34.6-4 Display from Highest to Lowest Grades by Student, and in Alphabetical Order
        5. Exercise 34.6-5 Archery at the Summer Olympics
        6. Exercise 34.6-6 The Five Best Scorers
        7. Exercise 34.6-7 Counting the Frequency of Vowels
      7. 34.7 Review Questions: True/False
      8. 34.8 Review Exercises
    5. Review in “Arrays in PHP”
      1. Review Crossword Puzzle
      2. Review Questions
  9. Part VII Subprograms
    1. Chapter 35 Introduction to Subprograms
      1. 35.1 What Exactly is a Subprogram?
      2. 35.2 What is Procedural Programming?
      3. 35.3 What is Modular Programming?
      4. 35.4 Review Questions: True/False
    2. Chapter 36 User-Defined Subprograms
      1. 36.1 Subprograms that Return a Value
      2. 36.2 How to Make a Call to a Function
      3. 36.3 Subprograms that Return no Values
      4. 36.4 How to Make a Call to a void Function
      5. 36.5 Formal and Actual Arguments
      6. 36.6 How Does a Function Execute?
        1. Exercise 36.6-1 Back to Basics – Calculating the Sum of Two Numbers
        2. Exercise 36.6-2 Calculating the Sum of Two Numbers Using Fewer Lines of Code!
      7. 36.7 How Does a void Function Execute?
        1. Exercise 36.7-1 Back to Basics – Displaying the Absolute Value of a Number
      8. 36.8 Review Questions: True/False
      9. 36.9 Review Exercises
    3. Chapter 37 Tips and Tricks with Subprograms
      1. 37.1 Can Two Subprograms use Variables of the Same Name?
      2. 37.2 Can a Subprogram Call Another Subprogram?
      3. 37.3 Passing Arguments by Value and by Reference
      4. 37.4 Passing and/or Returning an Array
      5. 37.5 Default Argument Values (Optional Arguments) and Named Arguments
      6. 37.6 The Scope of a Variable
      7. 37.7 Converting Parts of Code into Subprograms
      8. 37.8 Recursion
      9. 37.9 Review Questions: True/False
      10. 37.10 Review Exercises
    4. Chapter 38 More with Subprograms
      1. 38.1 Simple Exercises with Subprograms
        1. Exercise 38.1-1 A Simple Currency Converter
        2. Exercise 38.1-2 Finding the Average Values of Positive Integers
        3. Exercise 38.1-3 Finding the Sum of Odd Positive Integers
        4. Exercise 38.1-4 Finding the Values of y
      2. 38.2 Exercises of a General Nature with Subprograms
        1. Exercise 38.2-1 Validating Data Input Using a Subprogram
        2. Exercise 38.2-2 Sorting an Array Using a Subprogram
        3. Exercise 38.2-3 Progressive Rates and Electricity Consumption
        4. Exercise 38.2-4 Roll, Roll, Roll the… Dice!
        5. Exercise 38.2-5 How Many Times Does Each Number of the Dice Appear?
      3. 38.3 Review Exercises
    5. Review in “Subprograms”
      1. Review Crossword Puzzle
      2. Review Questions
  10. Part VIII Object-Oriented Programming
    1. Chapter 39 Introduction to Object-Oriented Programming
      1. 39.1 What is Object-Oriented Programming?
      2. 39.2 Classes and Objects in PHP
      3. 39.3 The Constructor and the Keyword $this
      4. 39.4 Passing Initial Values to the Constructor
        1. Exercise 39.4-1 Historical Events
      5. 39.5 Getter and Setter Methods
        1. Exercise 39.5-1 The Roman Numerals
      6. 39.6 Can a Method Call Another Method of the Same Class?
        1. Exercise 39.6-1 Doing Math
      7. 39.7 Class Inheritance
      8. 39.8 Review Questions: True/False
      9. 39.9 Review Exercises
    2. Review in “Object-Oriented Programming”
      1. Review Crossword Puzzle
      2. Review Questions
  11. Part IX Files
    1. Chapter 40 Introduction to Files
      1. 40.1 Introduction
      2. 40.2 Opening a File
      3. 40.3 Closing a File
      4. 40.4 Writing in (or Appending to) a File
      5. 40.5 The File Pointer
      6. 40.6 Reading from a File
      7. 40.7 Iterating Through the Contents of a File
      8. 40.8 Review Questions: True/False
      9. 40.9 Review Exercises
    2. Chapter 41 More with Files
      1. 41.1 Exercises of a General Nature with Files
        1. Exercise 41.1-1 Calculating the Sum of 10 Numbers
        2. Exercise 41.1-2 Calculating the Average Value of an Unknown Quantity of Numbers
        3. Exercise 41.1-3 Finding Minimum and Maximum Values
        4. Exercise 41.1-4 Concatenating Files
        5. Exercise 41.1-5 Searching in a File
        6. Exercise 41.1-6 Combining Files with Subprograms
      2. 41.2 Review Exercises
    3. Review in “Files”
      1. Review Crossword Puzzle
      2. Review Questions
  12. Some Final Words from the Author

Product information

  • Title: PHP and Algorithmic Thinking for the Complete Beginner
  • Author(s): Aristides Bouras
  • Release date: June 2024
  • Publisher(s): Packt Publishing
  • ISBN: 9781836209379