
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
508 Views
Here, we have set a function that adds "http:// to a string. Let’s say we have passed the following value −example.comAnd the output we want is with "http://" i.e. an actual link −http://example.com For this, you can use dot(.) notation and conditional match with preg_match().Example Live Demo Outputhttp://example.com ... Read More

AmitDiwan
187 Views
The PHP is a loosely typed language. When you match with case 0 the string matches with closest integer.Let’s say we have the following switch expression −switch ("match")Now, we will match with case 0 −case 0: echo " 0 with match"; break;We will also match for ... Read More

AmitDiwan
203 Views
Let’s say the following is our string −$sentence="This is my first PHP program";We want the following output −This is my first PHP ... gramWe shorten the string with “…”. For this, use the concept of substring() and set in a condition by checking the number of words −Example Live Demo ... Read More

AmitDiwan
2K+ Views
Let’s say the following is our variable wherein we have an .mp4 path file −$movieFileType="demo.mp4";To check whether the above file is video type, use end() along with explode(). You need to set this in strtolower() and check the condition −if(strtolower(end(explode(".", $movieFileType))) =="mp4") { } else { }Example ... Read More

AmitDiwan
1K+ Views
You can use the below syntax to access the value of a foreach.The syntax is as follows −foreach ($yourArrayName as &$anyVariableName)Let’s say we have the following array:$values= array(35, 50, 100, 75);We will now multiple each array value with 5 using the following PHP code −Example Live Demo Output175 250 500 375

AmitDiwan
23K+ Views
In order to get the root directory path, you can use _DIR_ or dirname().The syntax is as follows −echo _DIR_;The second syntax is as follows−echo dirname(__FILE__);Both the above syntaxes will return the same result.Example Live Demo Output/home/KOq8Zd /home/KOq8Zd

AmitDiwan
735 Views
To remove null value in PHP, use array_filter(). It filters the array values. Let’s say the following is our array −$studentDetails = array("firstName" => "John", "lastName"=> null); echo "The original value is=";print_r($studentDetails);Let’s filter with array_filter() −$result = array_filter($studentDetails);Example Live Demo OutputThe original value is=Array ( [firstName] => ... Read More

AmitDiwan
387 Views
To convert array to string, use the concept of implode () in PHP. Let’s say the following is our array −$sentence = array('My', 'Name', 'is', 'John');To convert the above array to string −, implode(" ", $sentence)Example Live Demo OutputThe string is = My Name is JohnLet us ... Read More

AmitDiwan
392 Views
We are required to write a function that takes in an array and returns an object with two arrays positive and negative. They both should be containing all positive and negative items respectively from the array.We will be using the Array.prototype.reduce() method to pick desired elements and put them into ... Read More