- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1046 Articles for PHP
149 Views
The ‘date_diff’ function can be used to get the difference between two dates. It is a built-in function that returns a DateInterval object if a specific number of days has been found, and returns False if the days is not found.Example Live DemoOutputThe day difference is: +60 daysTwo dates are defined using the ‘date_create’ function and the difference/ the number of days that are present between these two dates can be computed using the ‘date_diff’ function. It is assigned to a variable and printed on the console.
301 Views
To print continuous character pattern triangle in PHP, the code is as follows −Example Live DemoOutputA B C D E F G H I J K L M N O P Q R S T UThis is similar to generating a star or a number pattern, the only difference being, continuous characters of English alphabets are generated instead of stars or numbers. The function ‘continuous_alphabets’ is defined that takes the limit as a parameter. The limit value is iterated over and the character is printed and relevant line breaks are also generated in between. The function is called by passing this ... Read More
243 Views
To print continuous numbers in the form of triangle in PHP, the code is as follows −Elements Live DemoOutput1 2 3 4 5 6 7 8 9 10This is similar to generating a star or a number pattern, the only difference being, continuous numbers are generated instead of stars or repeated numbers. The function ‘continuous_pattern’ is defined that takes the limit as a parameter. The limit value is iterated over and the number is printed and increment. The relevant line breaks are also generated in between. The function is called by passing this limit value and the relevant output is generated on the console.
1K+ Views
To print the number pattern in PHP, the code is as follows −Example Live DemoOutput1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6This is similar to generating a star pattern, the only difference being, numbers are generated instead of stars. The function ‘num_pattern’ is defined that takes the limit as a parameter. The limit value is iterated over and the number is printed and relevant line breaks are also generated in between. The function is called by passing this limit value and the relevant output is generated on the console.
1K+ Views
Let us see an example to print a pattern of pyramid in PHP −Example Live DemoOutput * * * * * * * * * * * * * * * * * * * * * * * * * * * *A function named ‘print_pattern’ is defined that iterates through the number of rows through which the pattern needs to be generated. Relevant line breaks are also echoed using the ‘echo’ attribute. The function is called by passing the number of rows for which the pattern needs to be generated.
1K+ Views
Multidimensional arrays store multiple arrays whereas associative arrays store key-value pairs as data. Grouped relation between data can be stored in multidimensional associative arrays.Example Live DemoOutputJoe 20An array is defined that contains various attributes of an employee. The employee array is accessed based on the index names and the data is displayed on the console.
2K+ Views
The ‘rsort’ function can be used to check if an array is multidimensional or not. It takes one parameter, i.e the array that needs to be checked and returns yes or no depending on the nature of the array.Example Live DemoOutputIs the array multi-dimensional? bool(true)An array is defined that contains string elements. A function named ‘multi_dim’ is defined that sorts the elements of the array using ‘rsort’. The ‘isset’ function is then used to perform ‘AND’ operation on the elements of the array. This would help understand if the array has a single dimension or is multi-dimensional.Read More
359 Views
Using the ‘sizeof’ functionLet us see an example −Example Live DemoOutputThe array is empty!An array can be checked to see if it is empty or not in multiple ways. One method is to use the ‘sizeof’ function that sees if the array is empty. If yes, the size would be 0, thereby confirming the array being empty.Using the ‘empty’ functionExample Live DemoOutputThe array is non-empty The array is empty!Another method to check if an array is empty or not is to use the ‘empty’ function, that checks to see the contents of the array, and if nothing is present, says it is ... Read More
499 Views
To remove empty array elements in PHP, the code is as follows −Example Live DemoOutputAfter removing null values from the array, the array has the below elements -This 91 102 is a sampleAn array is defined, that contains strings, numbers and ‘null’ values. The ‘foreach’ loop is used to iterate over the elements and if a value is empty, i.e. it contains null, then it is deleted from the array. The relevant array is displayed again that wouldn’t contain null values.
672 Views
To merge duplicate values into multi-dimensional array in PHP, the code is as follows −Example Live DemoOutputThe unique array elements are Array ( [Cycling] => Array ( [0] => Array ( [Age] => 23 [name] => Joe [hobby] => Cycling ) [1] => Array ( [Age] => 30 [name] => Dev [hobby] => Cycling ) ... Read More