Programming Articles - Page 2195 of 3366

How to get a variable name as a string in PHP?

AmitDiwan
Updated on 26-Dec-2019 10:03:02

2K+ Views

To get a variable name as a string in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−This is it!ExampleLet us now see another example − Live DemoOutputThis will produce the following output−Val

Importance of Predicate interface in lambda expression in Java?

raja
Updated on 11-Jul-2020 12:38:14

2K+ Views

Predicate is a generic functional interface that represents a single argument function that returns a boolean value (true or false). This interface available in java.util.function package and contains a test(T t) method that evaluates the predicate of a given argument.Syntaxpublic interface Predicate {  boolean test(T t); }Exampleimport java.util.*; import java.util.functionPredicate; public class LambdaPredicateTest {    public static void main(String args[]) {       Employee emp1 = new Employee("Raja", 26);       Employee emp2 = new Employee("Jaidev", 24);       Employee emp3 = new Employee("Adithya", 30);       List empList = new ArrayList();       empList.add(emp1);       empList.add(emp2); ... Read More

How to re-index an array in PHP?

AmitDiwan
Updated on 26-Dec-2019 08:04:03

783 Views

To re-index an array in PHP, the code is as follows −Example Live DemoOutputThis will produce the following output−Array... Key = 0, Value = 150  Key = 1, Value = 100 Key = 2, Value = 120 Key = 3, Value = 110 Key = 4, Value = 115 Array after re-indexing Key = 2, Value = 150 Key = 3, Value = 100 Key = 4, Value = 120 Key = 5, Value = 110 Key = 6, Value = 115ExampleLet us now see another example − Live DemoOutputThis will produce the following output−Array... Key = a, Value = 150 Key = b, Value = 100 Key = c, Value = 120 Key = d, Value = 110 Key = e, Value = 115 Array after re-indexing Key = b, Value = 150 Key = c, Value = 100 Key = d, Value = 120 Key = e, Value = 110 Key = f, Value = 115

How to trim all strings in an array in PHP ?

AmitDiwan
Updated on 26-Dec-2019 08:11:27

1K+ Views

To trim all strings in an array in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−Array with leading and trailing whitespaces... Value = John Value = Jacob Value = Tom Value = Tim Updated Array... Value = John Value = Jacob Value = Tom Value = TimExampleLet us now see another example − Live DemoOutputThis will produce the following output−Array with leading and trailing whitespaces... Value = Kevin Value = Katie Value = Angelina Value = Jack Updated Array... Kevin Katie Angelina Jack

Sort an array of dates in PHP

AmitDiwan
Updated on 26-Dec-2019 08:08:28

3K+ Views

To sort an array of dates in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−Array (    [0] => 2019-08-10    [1] => 2019-09-08    [2] => 2019-10-10    [3] => 2019-11-11 )ExampleLet us now see another example − Live DemoOutputThis will produce the following output−Array (    [0] => 2019-11-11    [1] => 2019-11-11    [2] => 2019-10-10    [3] => 2019-09-08    [4] => 2019-05-11    [5] => 2019-01-01 )

How to find a maximum value in a collection using method reference in Java?

raja
Updated on 11-Jul-2020 12:29:58

229 Views

A method reference provides a way in the lambda expression to refer a method without executing it. It requires a target type context that consists of a compatible functional interface.Syntax :: In the below example, we can find out the maximum value of an ArrayList using method reference.Exampleimport java.util.*; class MyClass {    private int val;    MyClass(int v) {       val = v;    }    int getVal() {       return val;    } } public class MethodReferenceMaxValueTest {    static int compareMaxValue(MyClass a, MyClass b) {       return a.getVal() - b.getVal();    }    public ... Read More

PHP to check substring in a string

AmitDiwan
Updated on 24-Dec-2019 12:27:56

261 Views

To check substring in a string, the code is as follows in PHP −Example Live DemoOutputThis will produce the following output−String = How I Met Your Mother Substring = Mother Substring found successfullyExampleLet us now see another example − Live DemoOutputThis will produce the following output−String = In the Heart of Sea Substring = Ocean Substring not found

How to add days to $Date in PHP?

AmitDiwan
Updated on 24-Dec-2019 12:25:04

3K+ Views

To add days to $Date in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−Displaying date... Date = 2019-11-11 Displaying updated date... 2019-12-01ExampleLet us now see another example − Live DemoOutputThis will produce the following output−Displaying Date...2019/11/11 Displaying Updated Date... 2019/12/06

How to convert string to boolean in PHP?

AmitDiwan
Updated on 24-Dec-2019 12:22:19

772 Views

To convert string to boolean in PHP, the code is as follows. Use the filter_val() method−Example Live DemoOutputThis will produce the following output−Displaying Sunday as first day of a week... First day (next week) = Sunday - 15/12/2019 bool(false)ExampleLet us now see another example − Live DemoOutputThis will produce the following output−bool(false) bool(true) bool(false) bool(false)

How to get first day of week in PHP?

AmitDiwan
Updated on 24-Dec-2019 12:20:17

2K+ Views

To get the first day of the week in PHP, the code is as follows −Example Live DemoOutputThis will produce the following output −First day = Monday - 09/12/2019ExampleLet us now see another example − Live DemoOutputThis will produce the following output −Displaying Sunday as first day of a week... First day (next week) = Sunday - 15/12/2019

Advertisements