Tech Study

250+ PHP Programs for Practice | PHP Tutorial with Solutions

PHP Tutorial

PHP Tutorial provides in-depth knowledge about the Server side scripting language i.e. PHP. Using these PHP programs for practice you will learn PHP in a fun and easy way.

What is PHP ?

  • PHP stands for Hypertext Preprocessor
  • PHP is interpreted by the compiler and not compiled, which means that PHP is interpreted while executing and not while the code is compiled, hence PHP is a interpreted language and not a compiled language
  • PHP is a light weight language and is faster then other languages like ASP and JSP
  • PHP is an Object Oriented programming language
  • PHP is executed on the server side
  • Latest version of PHP is PHP 7.4.0 at the time of writing this article
  • PHP is an Open Source language
  • PHP is a loosely typed language – This means that PHP will allow to declare any kind of variables without specifying there datatypes.

What are the top PHP frameworks ?

  • Laravel – Laravel is a PHP framework which works in an MVC pattern, it is an ORM framework as well
  • Cake PHP 2
  • Cake PHP 3
  • Codeigniter
  • Symphony
  • Zend

What databases can be used with PHP ?

PHP supports the following databases:

  • MySQL – It is a Relational Database Management System (RDBMS) which allows to create tables for storing data
  • MongoDB – It is a Object based Database which does not follows relations instead it stores the data in JSON documents
  • Postgres SQL – It is a mixture of both Relational and Object based Database System which allows data to be stores in both tables and JSON documents
  • SQL Server – It is a Relational Database Management System(RDBMS) which similar to MySQL allows to create tables for storing data
  • Oracle – It is a Relational Database Management System(RDBMS) but with a lot of enhanced features which can help create quick reports like in an ERP system.

What is required to run PHP ?

You need to install the web server on your local machine to starting working on PHP.As PHP is a server side scripting language, Web server is a pre-requisite to start learning PHP.

You can install XAMPP to start the development.

List of PHP Programs for Practice

Below you will find the list of PHP programs, question for practice for becoming a PHP developer.

Basic PHP programs for Practice | PHP Coding Practice with examples

  1. How to write PHP code in different ways?
  2. How to write comments in PHP?
  3. How to use Codeignitor (PHP)?
  4. How to echo HTML in PHP?
  5. How to do Error handling in PHP?
  6. How to show All Errors in PHP?
  7. How to Start and Stop a Timer in PHP?
  8. How to create default function parameter in PHP?
  9. How to check if mod_rewrite is enabled in PHP?
  10. How to do Web Scrapping in PHP Using Simple HTML DOM Parser?
  11. How to pass form variables from one page to another page in PHP?
  12. How to display logged in user information in PHP?
  13. How to find out where a function is defined using PHP?
  14. How to Get $_POST from multiple check-boxes?
  15. How to Secure hash and salt for PHP passwords?
  16. How to detect search engine bots with PHP?
  17. How to set PHP development environment in windows?
  18. How to turn off PHP Notices?
  19. How to use ‘<?=’ short open tag in PHP programming?
  20. Write a PHP script to display ‘Hello World!’
  21. Create a HTML form that accept the user name and display the name using php
  22. Write a PHP script to get the client IP address
  23. Write a simple PHP browser detection script
  24. Write a PHP script, which changes the color of the first character of a word
  25. Write a PHP script to redirect a user to a different page
  26. Write a simple PHP program to check that email id is valid or not
  27. Write a PHP script to display string, values within a table
  28. Write a PHP function to test whether a number is greater than 30, 20 or 10 using ternary operator
  29. Write a PHP program to swap two variables
  30. Write a PHP program to check if a number is an Armstrong number or not
  31. Write a PHP program to convert word to digit
  32. Write a PHP program to remove duplicates from a sorted list
  33. Write a PHP program to compute the sum of the prime numbers less than 200
  34. Write a PHP program to print out the multiplication table upto 5*5
  35. Write a PHP program to compute the sum of the digits of a number
  36. Write a PHP program that multiplies corresponding elements of two given lists
  37. Write a PHP program to find the Fibonacci series

Array Programs

  1. How to insert a new item in an array on any position in PHP?
  2. How to append one array to another in PHP?
  3. How to delete an Element From an Array in PHP?
  4. How to print all the values of an array in PHP?
  5. How to perform Array Delete by Value Not Key in PHP?
  6. How to remove Array Element and do Re-Indexing in PHP?
  7. How to count all array elements in PHP?
  8. How to insert an item at the beginning of an array in PHP?
  9. How to check if two arrays contain the same elements?
  10. How to merge two arrays keeping original keys in PHP?
  11. How to find the maximum and the minimum in a PHP array?
  12. How to check a key exists in an array in PHP?
  13. How to find the second most frequent element in a PHP array?
  14. How to sort an array of objects by object fields in PHP?
  15. How to sort an array of strings in natural and standard orders?
  16. How to print the last value of an array without affecting the pointer?
  17. How to merge the first index of an array with the first index of the second array?
  18. How to create a string by joining the array elements using PHP?
  19. How to sort an Array of Associative Arrays by Value of a Given Key in PHP?
  20. How to make a leaderboard using PHP?
  21. How to check an array is multidimensional or not in PHP?
  22. How to create Multidimensional Associative Array in PHP?
  23. How to merge the duplicate value in multidimensional array in PHP?
  24. How to convert multidimensional array to XML file in PHP?
  25. How to search by multiple key => value in PHP array?
  26. How to search by key=>value in a multidimensional array in PHP?
  27. How to write a PHP program to find the Standard Deviation of an array?
  28. How to write PHP program to check for Anagram?
  29. Write a PHP script which will display the Cars in the following way using array
  30. Write a PHP script to get the Second element of the above array
  31. Write a PHP script that inserts a new item in an array in any position
  32. Write a PHP script to calculate and display average temperature, five lowest and highest temperatures
  33. Write a PHP script which displays all the numbers between 50 and 150 that are divisible by 4
  34. Write a PHP script to get the shortest/longest string length from an array
  35. Write a PHP script to generate unique random numbers within a range
  36. Write a PHP function that returns the lowest integer that is not 0
  37. Write a PHP script to sort an array in reverse order (highest to lowest)
  38. Write a PHP function to set union of two arrays

Function Programs

  1. How to pass PHP Variables by reference?
  2. How to format Phone Numbers in PHP?
  3. How to use php serialize() and unserialize() Function
  4. How to implement callback in PHP?
  5. How to merge two or more arrays using array_merge()?
  6. How to print an arithmetic progression series using inbuilt functions in PHP?
  7. How to prevent SQL Injection in PHP?
  8. How to extract the user name from the email ID using PHP?
  9. How to count rows in MySQL table in PHP?
  10. How to parse a CSV File in PHP?
  11. How to generate simple random password from a given string using PHP?
  12. How to upload images in MySQL using PHP PDO?
  13. How to check foreach Loop Key Value in PHP?
  14. How to properly Format a Number With Leading Zeros in PHP?
  15. How to get a File Extension in PHP?
  16. How to build a Grocery Store Web App using PHP with MySQL?
  17. How to delete text from file using preg_replace() function in PHP?

Date Programs

  1. How to get the current Date and Time in PHP?
  2. How to change the date format using PHP?
  3. How to convert DateTime to String using PHP?
  4. How to get Time Difference in Minutes in PHP?
  5. How to return all dates between two dates in an array in PHP?
  6. How to sort an array of dates in PHP?
  7. How to get the time of the last modification of the current page in PHP?
  8. How to convert a Date into Timestamp using PHP?
  9. How to add 24 hours to a unix timestamp in PHP?
  10. How to sort a multidimensional array by date element in PHP?
  11. How to convert timestamp to readable date/time in PHP?
  12. How to find number of week days between two dates?
  13. How to convert string to Date and DateTime in PHP?
  14. How to get last day of a month from date in PHP?

String Programs

  1. How to change strings in an array to uppercase?
  2. How to convert first character of all the words uppercase using PHP?
  3. How to get the last character of a string in PHP?
  4. How to convert uppercase string to lowercase using PHP?
  5. How to extract Numbers From a String in PHP?
  6. How to replace String in PHP?
  7. How to Encrypt and Decrypt a PHP String?
  8. How to display string values within a table using PHP?
  9. How to write Multi-Line Strings in PHP?
  10. How to check if a String Contains a Substring in PHP?
  11. How to append a string in PHP?
  12. How to remove white spaces only beginning/end of a string using PHP?
  13. How to Remove Special Character from String in PHP?
  14. How to create a string by joining the array elements using PHP?
  15. How to prepend a string in PHP?
  16. How to replace a word inside a string in PHP?
  17. How to remove all white spaces from a string in PHP?
  18. How to count the number of words in a string in PHP?
  19. How to find number of characters in a string in PHP?
  20. How to get a substring between two strings in PHP?
  21. How to get a variable name as a string in PHP?
  22. How to remove occurrences of a specific character from end of a string in PHP?
  23. How to convert string to boolean in PHP?
  24. How to generate Random String Using PHP?
  25. How to generate a random, unique, alphanumeric string in PHP?
  26. How to remove new lines from string in PHP?
  27. How to insert string at specified position in PHP?
  28. How to check a string is a rotation of another string?
  29. Write a PHP script to convert lowercase string to uppercase
  30. Write a PHP script to convert uppercase string to lowercase
  31. Write a PHP script to convert first character uppercase
  32. Write a PHP script to convert first character of all the words uppercase
  33. Write a PHP script split the following string
  34. Write a PHP script to extract the user name from the email ID
  35. Write a PHP script to get the last three characters of a string
  36. Write a PHP script to replace the first ‘the’ of the following string with ‘best’
  37. Write a PHP script to generate simple random password from a given string
  38. Write a PHP script to print the next character of a specific character
  39. Write a PHP script to remove a part of a string from the beginning
  40. Write a PHP script to insert a string at the specified position in a given string
  41. Write a PHP script to remove all leading zeroes from a string
  42. Write a PHP script to remove comma(s) from the following numeric string
  43. Write a PHP script to get the first word of a sentence
  44. Write a PHP script to print letters from ‘a’ to ‘z’
  45. Write a PHP script to select first 6 words from the following string

Classes Programs

  1. How to use PHP Access Specifiers?
  2. How to use PHP Constructors and Destructors?
  3. How to do Type Casting?
  4. How to convert of an Object to an Object of other class?
  5. How to merge two PHP objects?
  6. How to use Abstract Classes in PHP?

JSON Programs

  1. How to parse a JSON File in PHP?
  2. How to generate JSON File in PHP?
  3. How to Convert JSON file into CSV in PHP?
  4. How to Convert XML data into JSON using PHP?
  5. How to Insert JSON data into MySQL database using PHP?
  6. How to convert PHP array to JavaScript or JSON?
  7. How to receive JSON POST with PHP?
  8. How to use cURL to Get JSON Data and Decode JSON Data in PHP?

File Systems Programs

  1. How to Create a Folder if It Doesn’t Exist in PHP?
  2. How to check if File Exists in PHP?
  3. How to write Into a File in PHP?
  4. How to delete all files from a folder using PHP?
  5. How to get file name from a path in PHP?
  6. How to log errors and warnings into a file in PHP?
  7. How to extract extension from a filename using PHP?
  8. How to get names of all the subfolders and files present in a directory using PHP?

 

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more