Found 26504 Articles for Server Side Programming

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

256 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.

map equal_range() in C++ STL

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

240 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

232 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

Multiset in C++ Standard Template Library (STL)

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

213 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

multiset lower_bound() in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 14:05:36

351 Views

In this tutorial, we will be discussing a program to understand multiset lower_bound() in C++ STL.The function lower_bound() returns the first existence of the element in the container equivalent to the provided parameter, else it returns the element immediately bigger than that.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(1);    s.insert(2);    s.insert(2);    s.insert(1);    s.insert(4);    cout

multiset upper_bound() in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 14:00:38

348 Views

In this tutorial, we will be discussing a program to understand multiset upper_bound() in C++ STL.The function upper_bound() returns the pointer to an element which is bigger than the one provided as a parameter, else it returns the pointer to the last element in the container.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(1);    s.insert(3);    s.insert(3);    s.insert(5);    s.insert(4);    cout

negative_binomial_distribution in C++ with Examples

Ayush Gupta
Updated on 06-Apr-2020 13:58:33

187 Views

In this tutorial, we will be discussing a program to understand negative_binomial_distribution in C++.This function follows the negative Binomial discrete distribution and produces integers according to this random distribution.Example Live Demo#include using namespace std; int main() {    //setting number of experiments    const int exps = 10000;    const int numberstars = 100;    default_random_engine generator;    negative_binomial_distribution distribution(4, 0.5);    int p[10] = {};    for (int i = 0; i < exps; ++i) {       int counting = distribution(generator);       if (counting < 10)          ++p[counting];    }    cout

multiset max_size() in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 13:55:35

139 Views

In this tutorial, we will be discussing a program to understand multiset max_size() in C++ STL.The function max_size() returns the maximum number of elements a given container can hold.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(10);    s.insert(13);    s.insert(13);    s.insert(25);    s.insert(24);    cout

multiset size() in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 13:53:28

125 Views

In this tutorial, we will be discussing a program to understand multiset size() in C++ STL.The function size() returns the number of elements present into a given container.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(10);    s.insert(13);    cout

Advertisements