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
Server Side Programming Articles - Page 1523 of 2650
595 Views
To add backslash inside array of strings, use json_encode().Let’s say the following is our array −$value = [ "ADD", "REMOVE","SELECT","MODIFY" ];We want the output with backslash inside array of strings i.e −"[\"ADD\",\"REMOVE\",\"SELECT\",\"MODIFY\"]"ExampleThe PHP code is as follows − Live Demo OutputThis will produce the following output"[\"ADD\",\"REMOVE\",\"SELECT\",\"MODIFY\"]"
194 Views
If you want to remove extra whitespace from the beginning, use ltrim() in PHP. Let’s say the following is our variable −$value=" Hello, welcome to PHP Tutorial ";We want the output with no whitespace on the left −Hello, welcome to PHP TutorialExample Live Demo OutputThis will produce the following outputThe actual value is= Hello, welcome to PHP Tutorial The actual length is=34 After removing extra whitespace from beginning=32 The result is=Hello, welcome to PHP Tutorial
148 Views
Yes, change the date format in PHP using the date() along with strtotime(). Let’s say the following is our date −$dateValue = "2020-09-19";Change the date format using the strtotime() method −$modifiedDate= date("d-m-Y", strtotime($dateValue)); Example Live Demo OutputThis will produce the following outputThe original date format is=2020-09-19 The changed date format is= 19-09-2020
418 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 This will produce the following outputOutputThe value is=550000
935 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 this way, you will get the number of false values and same for true.Example Live Demo OutputThis will produce the following outputNumber of false value=5 Number of true value=4
216 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 ) ) )
834 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
339 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 value of next will reflect the current value because of => Next Value=45000 Current Value=45000
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 OutputAll Keys are as follows= firstName lastName countryName