Skip to content

Repository files navigation

🐘 PHP Coding Practice

A comprehensive collection of PHP practice scripts covering core programming concepts, data structures & algorithms (DSA), Object-Oriented Programming (OOP), string & array manipulation, and common coding interview problems.


📁 Repository Structure

php-coding-practice/
│
├── 📂 oops/                       # Object-Oriented Programming (OOP) concepts
│   ├── abstract.php              # Abstract classes and methods
│   ├── encapsulation.php         # Encapsulation & Data Hiding (private properties, getters/setters)
│   ├── inheritance.php           # Class inheritance and constructor overriding (`parent::__construct`)
│   ├── index.php                 # Access modifiers (`protected` method access in child classes)
│   └── oops.php                  # Class, object instantiation, and `__construct` lifecycle
│
├── 📂 questions/                  # Problem-solving & interview coding questions
│   ├── countVowels.php           # Vowel counter in strings using OOP approach
│   ├── palindrome.php            # Palindrome string checker (custom reversal logic)
│   ├── secondSmallest.php        # Find 2nd smallest element in an array (bubble sort logic)
│   ├── smallest_missing.php      # Find the smallest missing positive integer
│   ├── str_alpha.php             # Alphabetical sorting of characters in a string
│   ├── str_ch_count.php          # Character frequency counter in a string
│   ├── sum_of_even.php           # Sum of all even numbers in an array
│   └── sumOfEvenSquares.php      # Sum of squares of even numbers in an array
│
├── 📂 table/                      # Mini Interactive Web Projects
│   └── index.php                 # Dynamic Multiplication Table Generator (Bootstrap 5 + PHP Form)
│
├── array_short.php               # Custom Bubble Sort algorithm for arrays
├── array_unique.php              # Custom unique array values filter (without `array_unique`)
├── compare_array.php             # Array comparison, unique merging, and duplicate counter
├── implode_explode.php           # String splitting and array joining (`explode` / `implode`)
├── index.php                     # PHP basics ($ vs $$, echo vs print, strict comparison)
├── ip_address.php                # Client IP detection (HTTP headers & REMOTE_ADDR)
├── isPrime.php                   # Prime number finder (1 to 100)
├── pattern.php                   # Star & number pattern generators (Pyramid, Right Triangle)
├── power.php                     # Iterative power calculation ($x^y$ with negative exponent support)
├── recursive_function.php        # Recursive power calculation ($base^{exponent}$)
├── searching_array.php           # Linear search implementation in arrays
├── space_cal.php                 # Space character counter in strings
└── string_rev.php                # Word-level string reversal without built-in functions

📚 Categorized Overview

1. ⚙️ Core PHP & Fundamentals

File Topic / Description
index.php Variables vs Reference variables ($ vs $$), echo vs print, strict type comparison (===).
implode_explode.php Array to string conversion and vice-versa using implode() and explode().
ip_address.php Client IP detection using HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR, and REMOTE_ADDR.
space_cal.php Custom loop logic to count whitespace occurrences in a string.

2. 🧮 Algorithms & Data Structures (DSA)

File Topic / Description
array_short.php Manual sorting implementation (Bubble Sort) without built-in sort functions.
array_unique.php Extract unique values from an associative/indexed array manually.
compare_array.php Compare two arrays, merge distinct values, and count duplicates.
searching_array.php Linear search implementation with index tracking.
isPrime.php Generates and separates prime vs non-prime numbers up to 100.
power.php Iterative calculation of exponents (supports negative exponents and 0).
recursive_function.php Recursive exponent calculation with base cases.
pattern.php Number patterns, right-aligned star triangles, and pyramid patterns.
string_rev.php Custom word-order string reversal.

3. 🏛️ Object-Oriented Programming (OOP)

File Topic / Description
oops/oops.php Class definition, object creation, properties, and __construct() lifecycle.
oops/inheritance.php Inheritance (extends) and calling parent constructors using parent::__construct().
oops/abstract.php Abstract classes, abstract method declarations, and concrete child implementations.
oops/encapsulation.php Data encapsulation using private properties with public accessor methods.
oops/index.php Access modifiers: Accessing protected parent methods through derived classes.

4. 💡 Interview & Problem Solving (questions/)

File Problem Statement / Logic
questions/countVowels.php Counts vowels in strings using an OOP class structure.
questions/palindrome.php Checks if a given string is a palindrome without built-in string reverse functions.
questions/secondSmallest.php Finds the 2nd smallest element in an array with validation for array size.
questions/smallest_missing.php Finds the smallest missing positive integer from an array containing positive/negative numbers.
questions/str_alpha.php Cleans string and sorts characters alphabetically using nested loops.
questions/str_ch_count.php Calculates frequency of each character in a given string.
questions/sum_of_even.php Filters and computes the sum of all even numbers in an array.
questions/sumOfEvenSquares.php Computes the sum of squares of all even numbers in an array.

5. 🌐 Interactive Mini Apps (table/)

File Description
table/index.php Interactive web page with Bootstrap 5 styling to generate multiplication tables with input validation.

🚀 How to Run

Option 1: Using PHP Built-in Server (Recommended for Web UI)

Navigate to the root directory and start the built-in development server:

php -S localhost:8000

Open your browser and navigate to:

  • Root files: http://localhost:8000/<file_name>.php (e.g., http://localhost:8000/pattern.php)
  • OOP examples: http://localhost:8000/oops/<file_name>.php
  • Questions: http://localhost:8000/questions/<file_name>.php
  • Table app: http://localhost:8000/table/index.php

Option 2: Using PHP CLI (Command Line)

You can directly run any CLI-compatible PHP script:

php array_short.php
php questions/smallest_missing.php
php oops/abstract.php

Option 3: Using Local Server (XAMPP / WAMP / Laragon)

  1. Copy/Clone the repository folder into your server's web root (htdocs or www).
  2. Start Apache via your server control panel.
  3. Open http://localhost/php-coding-practice/ in your browser.

🛠️ Requirements

  • PHP 7.4 or PHP 8.x
  • Any web browser (for HTML/Bootstrap outputs)

About

A comprehensive PHP practice repository featuring core PHP fundamentals, Object-Oriented Programming (OOP), Data Structures & Algorithms (DSA), and coding interview questions.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages