Found 1046 Articles for PHP

How to get numeric index of associative array in PHP?

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

797 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

How to get file name from a path in PHP?

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

711 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

461 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

662 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

10K+ 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

243 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

412 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

108 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

114 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

Advertisements