
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
AmitDiwan has Published 10744 Articles

AmitDiwan
407 Views
You can use any of them, but a more professional approach is using the ternary operator (?). Performance of both if-else and ternary operator is the same.Let’s say we have the following two variable values −$value1=10; $value2=0;We need to compare the above 2 variable values.Example Live Demo ... Read More

AmitDiwan
910 Views
Let’s say the following is our array −$isMarriedDetails = [ false, true, false, true, true, false, false, true, false ];To count true and false values from an array, at first, count total values and subtract the number of true results. In ... Read More

AmitDiwan
211 Views
For this, use foreach loop along with [] and implement arary_values() method.Example Live Demo OutputArray ( [0] => Array ( [0] => Array ( [LASTNAME] => Doe [FIRSTNAME] => John ) ) [1] => Array ( [0] => Array ( [LASTNAME] => Miller [FIRSTNAME] => David ) ) )

AmitDiwan
822 Views
No, you cannot define constant in class constructor, you can use constant at the class level.Let’s say we have the following class −class ConstantDemo { }Define a constant in the class −class ConstantDemo { const LANGUAGE_NAME="PHP"; } Example Live Demo OutputThe language Name is=PHP

AmitDiwan
329 Views
Let’s say we have the following value −$nextValue=100;Let us take a new variable and assign a reference −$currentValue = &$nextValue;To assign a reference, use the reference assignment operator i.e. =&$anyVariableName in PHP.The PHP code is as follows −Example Live Demo OutputNext Value=100 Current Value=100 After changing the ... Read More

AmitDiwan
6K+ Views
Let’s say the following is our object −$employeeDetails = (object) [ 'firstName' => 'John', 'lastName' => 'Doe', 'countryName' => 'US' ];We want the following output i.e. only the keys −firstName lastName countryNameTo display only the keys from an object, use array_keys() in PHP.Example Live Demo ... Read More

AmitDiwan
468 Views
To convert timestamp to string, use setTimestamp(). Let’s say the following is our input i.e. timestamp −$SQLTimestamp = 1600320600000;We want the following output i.e. Date string −2020-09-17 05:30:00At first, get seconds from Timestamp −$seconds = round($SQLTimestamp/1000, 0);Example Live Demo Output2020-09-17 05:30:00

AmitDiwan
2K+ Views
Let’s say we have the following array −$namesArray = ['John', 'Adam', 'Robert'];We want the following output i.e. an associative array from the above array −Array ( [John] => Array ( [Adam] => Array ( [Robert] => Smith ) ) )Example Live Demo OutputArray ( [John] => Array ( [Adam] => Array ( [Robert] => Smith ) ) ) Doe

AmitDiwan
1K+ Views
For this, use the foreach loop and insert into statement in order to insert all combinations of values in PHP arrays.Let’s say we have the following arrays −$name1 = ["John", "Mike"]; $name2 = ["David", "Sam"]; $name3 = ["Bob", "Adam"];Example Live Demo