PHP Examples

  • Last Updated : 08 Oct, 2021

The following PHP section contains a wide collection of PHP programming examples. The PHP examples are categorized based on the topics, including array, function, date, string, JSON, file system, and many more. Each example includes multiple approaches to solve the problem.

PHP Examples
PHP Programming Tutorial
Recent articles on PHP
PHP Output & Multiple Choice Questions

Topics

Basic Programs

  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?

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?

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?

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?



My Personal Notes arrow_drop_up


Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.