AmitDiwan has Published 10744 Articles

Create nested JSON object in PHP?

AmitDiwan

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

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

AmitDiwan

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

255 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 ... Read More

PHP string cast vs strval function, which one should I use?

AmitDiwan

AmitDiwan

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

953 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 ... Read More

Perform simple validation in MongoDB?

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 14:09:04

271 Views

For validation in MongoDB, use validator. Following is the query to create validation on collection in MongoDB −> db.createCollection( "demo437" , { ...    validator: { $jsonSchema: { ...       bsonType: "object", ...       required: [ "FirstName", "LastName"], ...       properties: { ...   ... Read More

Fetch a specific record using a single MySQL query with AND & OR operator

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 14:00:14

140 Views

Let us first create a table −mysql> create table DemoTable2015    -> (    -> StudentId int,    -> StudentName varchar(20),    -> StudentCountryName varchar(20) -> ); Query OK, 0 rows affected (1.20 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2015 values(1, ... Read More

Calculating byte values to megabyte (MB) in MySQL?

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 13:44:41

2K+ Views

Here, we are taking BIGINT type, since it takes 8 byte signed integer. Let us first create a table with column as BIGINT type −mysql> create table DemoTable2031    -> (    -> ByteValue bigint    -> ); Query OK, 0 rows affected (1.17 sec)Insert some records in the table ... Read More

Find maximum value from a VARCHAR column in MySQL

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 13:43:16

1K+ Views

To find maximum value, use MAX() along with CAST(), since the values are of VARCHAR type. Let us first create a table −mysql> create table DemoTable2030    -> (    -> Value varchar(20)    -> ); Query OK, 0 rows affected (0.44 sec)Insert some records in the table using insert ... Read More

Update the content of a specific cell in MySQL

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 13:42:37

634 Views

Let us first create a table −mysql> create table DemoTable2029    -> (    -> Id int,    -> FirstName varchar(20),    -> LastName varchar(20)    -> ); Query OK, 0 rows affected (0.98 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2029 values(1, 'Chris', 'Brown') ... Read More

How to create a thumbnail image CSS?

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 13:41:40

681 Views

Following is the code to create a thumbnail image using CSS −Example Live Demo img {    border: 3px solid rgb(208, 255, 0);    border-radius: 4px;    width: 150px;    height: 150px; } img:hover {    box-shadow: 2px 2px 4px 2px rgb(60, 255, 53); } ... Read More

Advertisements