Programming Articles - Page 2034 of 3363

PHP - How to use $timestamp to check if today is Monday or 1st of the month?

AmitDiwan
Updated on 07-Apr-2020 11:06:19

1K+ Views

The date function can be used to return the string formatted based on the format specified by providing the integer timestamp or the current time if no timestamp is givenThe timestamp is optional and defaults to the value of time().Example Live Demoif(date('j', $timestamp) === '1')    echo "It is the first day of the month today"; if(date('D', $timestamp) === 'Mon')    echo "It is Monday today";OutputThis will produce the following output −It is the first day of the month today

Create nested JSON object in PHP?

AmitDiwan
Updated on 07-Apr-2020 11:01:47

2K+ Views

JSON structure can be created with the below code −$json = json_encode(array(    "client" => array(       "build" => "1.0",       "name" => "xxxx",       "version" => "1.0"    ),    "protocolVersion" => 4,    "data" => array(       "distributorId" => "xxxx",       "distributorPin" => "xxxx",       "locale" => "en-US"    ) ));

Add PHP variable inside echo statement as href link address?

AmitDiwan
Updated on 07-Apr-2020 10:59:20

4K+ Views

HTML in PHPecho "Link";orecho "Link";PHP in HTML

How do I sort a multidimensional array by one of the fields of the inner array in PHP?

AmitDiwan
Updated on 07-Apr-2020 10:58:27

278 Views

The usort function can be used to sort a multidimensional array. It sorts with the help of a user defined function.Below is a sample code demonstration −Examplefunction compare_array($var_1, $var_2) {    if ($var_1["price"] == $var_2["price"]) {       return 0;    }    return ($var_1["price"] < $var_2["price"]) ? -1 : 1; } usort($my_Array,"compare_array") $var_1 = 2 $var_2 = 0OutputThis will produce the following output −1Explanation − We have declared var_1 and var)2 with integer values. They are compared and the result is returned.

How to reset the JShell session in Java 9?

raja
Updated on 07-Apr-2020 09:22:26

625 Views

Java 9 has introduced JShell for Java, and it allows us to evaluate code snippets such as declarations, statements, and expressions.During the JShell session, we need to reset it without closing and re-opening JShell then we can use the internal command: "/reset". By using this command, code entered during the current session has erased. It can be useful when we want to test new classes, create new variables, etc. while keeping the names previously used.In the below snippet, we have created variables x, y, and str. We can able to see all entered code snippets using the "/list" command. After that, we can apply ... Read More

map equal_range() in C++ STL

Ayush Gupta
Updated on 06-Apr-2020 14:19:45

267 Views

In this tutorial, we will be discussing a program to understand map equal_range in C++ STL.This function returns a pair of iterators that bounds the range of the container in which the key equivalent to the given parameter resides.Example Live Demo#include using namespace std; int main() {    //initializing container    map mp;    mp.insert({ 4, 30 });    mp.insert({ 1, 40 });    mp.insert({ 6, 60 });    pair       it;    it = mp.equal_range(1);    cout

Maximum of all Subarrays of size k using set in C++ STL

Ayush Gupta
Updated on 06-Apr-2020 14:16:34

250 Views

In this tutorial, we will be discussing a program to get maximum of all subarrays of size k using set in C++ STL.For this we will be provided with a array of size N and integer K. Our task is to get the maximum element in each K elements, add them up and print it out.Example Live Demo#include using namespace std; //returning sum of maximum elements int maxOfSubarrays(int arr[], int n, int k){    set q;    set::reverse_iterator it;    //inserting elements    for (int i = 0; i < k; i++) {       q.insert(pair(arr[i], i));    } ... Read More

Menu Driven C++ Program for a Simple Calculator

Ayush Gupta
Updated on 06-Apr-2020 14:15:19

1K+ Views

In this tutorial, we will be discussing a program to create a menu driven program for a simple calculator.This program will give user the ability to choose among the following mathematical operations − addition, subtraction, multiplication, division, HCF and LCM.Example Live Demo#include using namespace std; //displaying the menu void menu(){    cout

What are the different feedback modes in JShell in Java 9?

raja
Updated on 06-Apr-2020 14:22:14

246 Views

When performing an operation in the JShell tool, it displays a message in return (success of the command, error, and type of a variable created as well as its value). It has been customized using the command: "/set feedback". This command displays the type of return currently configured as well as the different return modes available.jshell> /set feedback | /set feedback normal | | Available feedback modes: | concise | normal | silent | verboseThere are four feedback modes available in JShell as listed below:1) /set feedback normal: This is the default JShell feedback. When we evaluate an expression, JShell returns the corresponding result and an ... Read More

Multiset in C++ Standard Template Library (STL)

Ayush Gupta
Updated on 06-Apr-2020 14:10:13

248 Views

In this tutorial, we will be discussing a program to understand Multiset in C++ STL (Standard Template Library).Multiset are associative containers much similar to sets. The one difference multiset holds is they can even contain duplicate values.Example Live Demo#include #include #include using namespace std; int main(){    multiset gquiz1;    //inserting values    gquiz1.insert(40);    gquiz1.insert(30);    gquiz1.insert(60);    gquiz1.insert(20);    gquiz1.insert(50);    gquiz1.insert(50);    gquiz1.insert(10);    multiset :: iterator itr;    cout

Advertisements