
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 26504 Articles for Server Side Programming

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

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

738 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] => John [lastName] => ) After removing null part,the result is=Array ( [firstName] => John )

389 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 now see another PHP code wherein we will add separator as well −Example Live Demo OutputThe string is = One*Two*Three

492 Views
Suppose we have a string s, we have to find the minimum number of characters needed to be inserted so that the string becomes a palindrome.So, if the input is like s = "mad", then the output will be 2, as we can insert "am" to get "madam".To solve this, we will follow these steps −Define a function dp(). This will take i, jif i >= j, thenreturn 0if s[i] is same as s[j], thenreturn dp(i + 1, j - 1)otherwise, return minimum of dp(i + 1, j) and dp(i, j - 1) + 1From the main method, do the ... Read More

249 Views
Suppose we have a binary tree, and we also have two numbers a and b, we have to find the value of the lowest node that has a and b as descendants. We have to keep in mind that a node can be a descendant of itself.So, if the input is likea = 6, b = 2, then the output will be 4To solve this, we will follow these steps −Define a method solve() this will take root and a, bif root is null, thenreturn -1if value of root is either a or b, thenreturn value of rootleft := solve(left ... Read More

293 Views
Suppose we have a lowercase string s and another value k. Now consider an operation where we perform a run-length encoding on a string by putting repeated successive characters as a count and character. So if the string is like "aaabbc" would be encoded as "3a2bc". Here we do not put "1c" for "c" since it only appears once successively. So we can first remove any k consecutive characters in s, then find the minimum length possible of the resulting run-length encoding.So, if the input is like s = "xxxxxyyxxxxxzzxxx", k = 2, then the output will be 6, as ... Read More

186 Views
Suppose we have a binary tree, we have to find the sum of the longest path from the root to a leaf node. If there are two same long paths, return the path with larger sum.So, if the input is likethen the output will be 20.To solve this, we will follow these steps −Define a function rec() . This will take currif curr is null, thenreturn(0, 0)bigger := maximum of rec(left of curr) , rec(right of curr)return a pair (bigger[0] + 1, bigger[1] + value of curr)From the main method do the following −ret := rec(root)return the 1th index of ... Read More

564 Views
Suppose we have a string s, we have to find the length of the longest substring that contains at most 2 distinct characters.So, if the input is like s = "xyzzy", then the output will be 4, as "yzzy" is the longest substring with at most 2 unique characters.To solve this, we will follow these steps−start := 0c := a mapans := 0for end in range 0 to size of s, doc[s[end]] := c[s[end]] + 1while size of c > 2, doc[s[start]] := c[s[start]] - 1if c[s[start]] is 0, thendelete c[s[start]]start := start + 1ans := maximum of ans and ... Read More

315 Views
Suppose we have a list of numbers called nums, we have to find the length of the longest sublist where 2 * minimum of sublist > maximum of sublist.So, if the input is like nums = [10, 2, 6, 6, 4, 4], then the output will be 4, as the sublist [6, 6, 4, 4] is the longest sublist that holds the criteria as 2 * 4 > 6.To solve this, we will follow these steps−ret := 0define two double ended queues minq and maxql := 0, r := 0while r < size of nums, don := nums[r]while minq and ... Read More