Get Numeric Index of Associative Array in PHP

AmitDiwan
Updated on 27-Dec-2019 07:39:23

928 Views

To get the numeric index of an associative array, the code is as follows−Example Live DemoOutputThis will produce the following output−Array key and value... key: a, value: 5 key: b, value: 20 key: c, value: 35 key: d, value: 55ExampleLet us now see another example− Live DemoOutputThis will produce the following output−Array key and value... key: p, value: 150 key: q, value: 100 key: r, value: 120 key: s, value: 110 Updated Array key and value... key: p, value: 150 key: q, value: 100 key: r, value: 120 key: s, value: 25

Get File Name from a Path in PHP

AmitDiwan
Updated on 27-Dec-2019 07:36:26

884 Views

To get the file name from a path, the code is as follows−Example Live DemoOutputThis will produce the following output−main.phpExampleLet us now see another example − Live DemoOutputThis will produce the following output−main

Get Current Function Name in PHP

AmitDiwan
Updated on 27-Dec-2019 07:34:12

654 Views

To get the current function name in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−Base class function! Base class function declared final!string(7) "display" Derived class function! Base class function declared final!string(7) "display"ExampleLet us now see another example − Live DemoOutputThis will produce the following output−Base class function!string(10) "Base::demo" Base class function declared final!string(7) "display" Derived class function! Base class function declared final!string(7) "display"

Delete Array Element Based on Key in PHP

AmitDiwan
Updated on 27-Dec-2019 07:30:56

764 Views

To delete an array element based on a key in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−Array with leading and trailing whitespaces... Value = John Value = Jacob Value = Tom Value = Tim Comma separated list... John , Jacob , Tom , Tim Updated Array... Value = John Value = Jacob Value = Tom Value = Tim Updated Array... Value = John Value = Tom Value = TimExampleLet us now see another example − Live DemoOutputThis will produce the following output. Now, an error would be visible since we deleted the element and trying to ... Read More

Zip Entry Read Function in PHP

karthikeya Boyini
Updated on 27-Dec-2019 07:29:57

84 Views

The zip_entry_read() function is used to get the contents from an open zip archive file.Syntaxzip_entry_read(zip_entry, len)Parameterszip_entry − The zip entry resource. Required.len − The length in bytes. The default is 1024.ReturnThe zip_entry_read() function Returns the contents from an open zip archive file. Returns FALSE on failure.ExampleThe following is an example. Let’s say our zip file "one.zip" is having only a single file i.e. "detail.txt" with the following content.Asia is a continent!Let us see an example −ExampleOutputText in the file = Asia is a continent!Read More

Search for Particular Strings in Comma-Separated Values in MySQL

AmitDiwan
Updated on 27-Dec-2019 07:11:07

628 Views

For this, use REGEXP. Let us first create a table −mysql> create table DemoTable1902    (    Subjects text    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1902 values('MongoDB, Java, Python'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1902 values('SQL Server, MySQL, PL/SQL'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1902 values('Hibernate, Spring, JPA'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1902;This will produce the following output −+-------------------------+ | Subjects ... Read More

Copy Records Between MySQL Tables with Different Columns

AmitDiwan
Updated on 27-Dec-2019 07:09:41

671 Views

For this you can use INSERT INTO SELECT statement. Let us first create a table −mysql> create table DemoTable1900    (    ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(20),    ClientAge int default 29    ) auto_increment=1000; Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1900(ClientName, ClientAge) values('Chris', 45); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1900(ClientName, ClientAge) values('David', 29); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1900(ClientName, ClientAge) values('Mike', 37); Query OK, 1 row affected (0.00 sec) mysql> insert into ... Read More

Sin Function in PHP

karthikeya Boyini
Updated on 27-Dec-2019 07:07:09

76 Views

The sin() function Returns the sine of a number.Syntaxsin(num)Parametersnum − The number for which you want to Return the sine. A value in radians.ReturnThe sin() function Returns the arc sine of a number.Example Live DemoOutput0.4794255386042-0.78332690962748ExampleLet us see another example − Live DemoOutput00.8414709848079-0.84147098480790.90929742682568

Replace Particular Character in a MySQL Column

AmitDiwan
Updated on 27-Dec-2019 07:06:24

382 Views

To replace a particular character, use REPLACE() and to update, use the UPDATE command. Let us first create a table −mysql> create table DemoTable1899    (    Code varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1899 values('John_123'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1899 values('32189_Sam_987'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1899 values('Miller_David_456_909'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1899;This will produce the following output ... Read More

Round Function in PHP

Samual Sam
Updated on 27-Dec-2019 07:05:22

210 Views

The round() function rounds a floating point number. For example, 0.90 to 1, 0.35 to 0, etc.Syntaxround(val, precision, mode)Parametersval − The value to roundprecision − It sets the precision i.e. the number of decimal digits to round tomode − A constant that specify the following rounding modePHP_ROUND_HALF_UP - The constant rounds val up to precision decimal, when it is half way there. Rounds 1.5 to 2 and -1.5 to -2. DefaultPHP_ROUND_HALF_DOWN - The constant rounds val down to precision decimal places, when it is half way there. Rounds 1.5 to 1 and -1.5 to -1PHP_ROUND_HALF_EVEN - It rounds val to ... Read More

Advertisements