
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
Found 33676 Articles for Programming

246 Views
Let’s say the following is our array −$marks=[45,67,89,34,98,57,77,30];And we want the output like this with only selected values45 67 89 68 98 57 77 60Above, we multiplied marks less than 40 with 2, rest kept the entire array same.ExampleThe PHP code is as follows Live Demo OutputThis will produce the following outputThe Marks are as follows 45 67 89 68 98 57 77 60

180 Views
Let’s say the following is our string with letters and numbers −$value ="1045632245555fghjklm67535454663443gfdjkbvc9890000006777743";We ant a specific value beginning from 989 i.e.−9890000006777743ExampleFor this, use substr() along with strpos(). Live Demo OutputThe actual value is=1045632245555fghjklm67535454663443gfdjkbvc9890000006777743 The filter value is=9890000006777743

351 Views
The syntax is as follows −$anyVariableName=yourCondition ? if condition becomes true then this will be executed: if condition becomes false then this gets executed;ExampleThe PHP code is as follows Live Demo OutputThis will produce the following outputGreater Than or Equal to 100

588 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\"]"

184 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

143 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

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 This will produce the following outputOutputThe value is=550000

912 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