Check If Today Is Monday or 1st of the Month Using Timestamp in PHP

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

Sort Multidimensional Array by Inner Array Field in PHP

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

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

List Files Recursively in C#

George John
Updated on 07-Apr-2020 10:06:49

2K+ Views

To get the list of files in a directory, use the SearchOptions.AllDirectories in C#.Firstly, set the directory for which you want the files −string[] myFiles = Directory.GetFiles("D:\New\", "*.*", SearchOption.AllDirectories);The following is an example displaying files from the above mentioned directory −Exampleusing System; using System.Linq; using System.IO; class Program {    static void Main() {       string[] myFiles = Directory.GetFiles("D:\New\", "*.*", SearchOption.AllDirectories);       foreach (string res in myFiles) {          Console.WriteLine(res);       }    } }OutputThe following is the output. It lists all the directories of the folder −D:\New\one.txt D:\New\two.html D:\Newature.png

Get the Number of Bytes in a File in C#

Ankith Reddy
Updated on 07-Apr-2020 10:04:34

479 Views

FileInfo type has a Length property that determines how many bytes a file has.Firstly, set the file −FileInfo file = new FileInfo("D:ew");Now use the Length property −file.LengthHere is the complete code −Exampleusing System; using System.Linq; using System.IO; class Program {    static void Main() {       FileInfo file = new FileInfo("D:ew");       long res = file.Length;       Console.WriteLine("Bytes: "+res);    } }OutputThe following is the output −3259244

Reset JShell Session in Java 9

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

600 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

PHP String Cast vs strval Function: Which One Should I Use?

AmitDiwan
Updated on 06-Apr-2020 14:35:36

945 Views

A value can be converted into a string with the help of (string) cast or the strval() function.The strval() function is a function call whereas (string) cast is an internal type casting method.Unless there is some specific dataset or use case, both of these can be used interchangeably.This is because PHP uses automatic type conversion, due to which a variable's type is determined based on the context in which it is used.The strval($var) function returns the string value of $var whereas the (string)$var explicitly converts the "type" of $var during the process of evaluation.The $var can be any scalar type ... Read More

Different Feedback Modes in JShell in Java 9

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

219 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

Map Equal Range in C++ STL

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

238 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

Advertisements