Found 26504 Articles for Server Side Programming

How to get file name from a path in PHP?

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

879 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

How to get current function name in PHP?

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

643 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"

How to delete an array element based on key in PHP?

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

756 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

Function Overloading and Overriding in PHP

AmitDiwan
Updated on 02-Jan-2020 06:36:33

13K+ Views

Function Overloading in PHPFunction overloading is a feature that permits making creating several methods with a similar name that works differently from one another in the type of the input parameters it accepts as arguments.ExampleLet us now see an example to implement function overloading− Live DemoOutputThis will produce the following output−9.42648Function Overriding in PHPIn function overriding, the parent and child classes have the same function name with and number of argumentsExampleLet us now see an example to implement function overriding− Live DemoOutputThis will produce the following output−Base class function! Base class function declared final! Derived class function! Base class function declared final!Read More

Generating Random String Using PHP

AmitDiwan
Updated on 26-Dec-2019 10:39:42

338 Views

To generate random string using PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−Displaying random string... 1c856ExampleLet us now see another example − Live DemoOutputThis will produce the following output−Displaying random string... a3541 Displaying another random string... 335b83d9e9

How to access an associative array by integer index in PHP?

AmitDiwan
Updated on 26-Dec-2019 10:37:25

473 Views

To access an associative array by integer index in PHP, the code is as follows−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: 110ExampleLet 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: 20 key: s, value: 10

How to check whether an array is empty using PHP?

AmitDiwan
Updated on 26-Dec-2019 10:34:39

182 Views

To check whether an array is empty, the code is as follows in PHP−Example Live Demo

How to create a copy of an object in PHP?

AmitDiwan
Updated on 26-Dec-2019 10:33:37

126 Views

To create a copy of an object in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−JackKevin TomRyanExampleLet us now see another example − Live DemoOutputThis will produce the following output−Demo Object(    [deptname] => Finance    [deptzone] => West ) Demo Object(    [deptname] => Finance    [deptzone] => West )

How to declare a global variable in PHP?

AmitDiwan
Updated on 02-Jan-2020 06:25:55

1K+ Views

A global variable can be accessed in any part of the program. However, in order to be modified, a global variable must be explicitly declared to be global in the function in which it is to be modified. This is accomplished, conveniently enough, by placing the keyword GLOBAL in front of the variable that should be recognized as global.ExampleThe code is as follows wherein we can see how to declare a global variable in PHP− Live DemoOutputThis will produce the following output−Value = 2ExampleLet us now see another example− Live DemoOutputThis will produce the following output−5

Merge two arrays keeping original keys in PHP

AmitDiwan
Updated on 26-Dec-2019 10:26:20

185 Views

To merge two arrays keeping original keys in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−array(8) {    ["p"]=> string(3) "150"    ["q"]=> string(3) "100"    ["r"]=> string(3) "120"    ["s"]=> string(3) "110"    ["t"]=> string(3) "115"    ["u"]=> string(3) "103"    ["v"]=> string(3) "105"    ["w"]=> string(3) "125" }ExampleLet us now see another example − Live DemoOutputThis will produce the following output−array(1) {    ["a"]=>    string(5) "Jacob" }

Advertisements