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 )
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.
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
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
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
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
A static filed/variable belongs to the class and it will be loaded into the memory along with the class. You can invoke them without creating an object. (using the class name as reference). There is only one copy of the static field available throughout the class i.e. the value of the static field will be same in all objects. You can define a static field using the static keyword.Examplepublic class Sample{ static int num = 50; public void demo(){ System.out.println("Value of num in the demo method "+ Sample.num); } public static void main(String ... Read More
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 records into the table with the help of insert command −mysql> insert into demo52 values(1, 'John'); Query OK, 1 row affected (0.17 sec) mysql> insert into demo52 values(2, 'David'); Query OK, 1 row affected (0.10 sec) mysql> insert into demo52 values(3, 'Mike'); Query OK, 1 row affected (0.13 ... Read More
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> insert into demo51(name) values('John'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo51(name) values('Bob'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo51(name) values('David'); Query OK, 1 row affected (0.35 sec) mysql> insert into demo51(name) values('Sam'); Query OK, 1 row affected (0.14 sec)Display ... Read More
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 extract the last digit from the year. Following is the query −select floor(@yourVariableName % 10);Following is the query to sum the digits of year −mysql> set @year_column_value = 2020; Query OK, 0 rows affected (0.00 sec) mysql> select −> floor(@year_column_value / 1000) −> + floor(@year_column_value % 1000 / 100) −> ... Read More