AmitDiwan has Published 10744 Articles

PHP How to cast variable to array?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 05:35:37

642 Views

To cast variable to array, use the below syntax −$yourNewVariableName=(array)$yourVariableName;The PHP code is as follows −Example Live Demo OutputArray ( [0] => Mike [1] => Sam [2] => David )

PHP How to display array values with text “even” to be displayed for even index values

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 05:34:16

146 Views

For this, you can use for loop along with some conditions.The PHP code is as follows −Example Live Demo OutputEven 1 Even 3 EvenAbove, for 0th index, the text “Even” is displayed and the same goes on for 2th and 4th index.

How to display array values with do while or for statement in my PHP?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 05:32:52

243 Views

Following is the syntax to display array valuesdo{    //statement1    //statement2    .    .    .    n } while(yourCondition);The PHP code is as follows −Example Live Demo OutputJohn David Mike Sam Carol

What happens if ++ operator is used with string value in PHP?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 05:31:22

128 Views

If you try to use ++ operator with string value then it increments the last character value with 1 and prints the ASCII value.Following is the PHP code −Example Live Demo OutputThe string modified value is=Joho The string incremented value is=11.5

strlen() php function giving the wrong length of unicode characters ?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 05:30:04

502 Views

To get the correct length, use mb_strlen() for Unicode characters.The PHP code is as follows −Example Live DemoOutputThe string length with mb_strlen=9 The string length with strlen=10

PHP Why does this && not trigger as false?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 05:27:49

95 Views

This is because if you use && both conditions must be true. If any one condition becomes false then the overall condition evaluates to false.The PHP code is as follows −Example Live Demo OutputThe above condition is true

How to join tables and fetch values from a MySQL database?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 13:23:28

427 Views

To join tables, use the JOIN concept in MySQL. At first, let us create two tables.Let us create the first table −mysql> CREATE TABLE `demo52` ( −> `id` INT NOT NULL, −> `name` VARCHAR(20) NOT NULL, −> PRIMARY KEY (`id`) −> ); Query OK, 0 rows affected (1.19 sec)Insert some ... Read More

Placing order according to the condition in MySQL?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 13:22:09

78 Views

For this, use ORDER BY CASE WHEN statement.Let us create a table −mysql> create table demo51 −> ( −> id int not null auto_increment primary key, −> name varchar(20) −> ); Query OK, 0 rows affected (1.08 sec)Insert some records into the table with the help of insert command −mysql> ... Read More

Sum of digits of year in MySQL?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 13:20:28

191 Views

At first, you need to extract the last digit and add the extracted value. And the same goes in till we get the sum of all digits of the year, for example, for the year 2020 −2 + 0 + 2 + 0 = 4The concept is as follows to ... Read More

Creating a table with a TIMESTAMP field in MySQL?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 13:18:46

7K+ Views

For this, you can use TIMESTAMP keyword in MySQL.Let us create a table −mysql> create table demo50 −> ( −> id int not null auto_increment primary key, −> start_date timestamp default current_timestamp not null, −> end_date timestamp default current_timestamp not null −> ); Query OK, 0 rows affected (1.35 sec)Insert ... Read More

Advertisements