AmitDiwan has Published 10744 Articles

Is it possible to combine PHP's filter_input() filter flags with AND/OR?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 09:19:05

181 Views

Yes, it is possible to combine filter_input() with AND/OR in PHP. This can be done by looping over the POST fields−$value = filter_input(INPUT_POST, 'field', FILTER_DEFAULT, is_array($_POST['field']) ? FILTER_REQUIRE_ARRAY : NULL);An equivalent for the same user for each loop has been shown below−$memory = array(); //looping through all posted values foreach($_POST ... Read More

How to configure PHPUnit testing?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 08:20:57

213 Views

PHPStorm can be used to test PHP applications using the PHPUnit testing framework.The PHP interpreter needs to be configured in phpstorm.The Composer should be installed and initialized with respect to the current project.Below are the steps to configure PHPUnit testing −Download phpunit.phar (manually or using the composer) and save it ... Read More

How to debug and log PHP OPcache Issues

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 08:15:34

498 Views

The OPCache can be temporarily disabled by adding the below code to the script−ini_set('opcache.enable', 0);This can be used to tell whether OPCache was the reason behind the script failing. Due to this, the user will not have to go through every extension and turn them on/off to see which extension ... Read More

Creating anonymous objects in PHP

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 08:14:17

591 Views

Beginning from PHP version 7, it has been made possible to create anonymous classes. Every object in PHP is associated with a class. The anonymous classes can be instantiated to create objects.Example Live DemoOutputDoes the instance belong to parent class? = bool(true)In the above code, a parent class (my_sample_class) has been ... Read More

How to set encoding in PHP FPDI library?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 08:13:21

895 Views

Below is the same code to set encoding for FPDI library−Add new fonts that have the correct alphabets.$pdf->AddFont('DejaVu', '', 'DejaVuSansCondensed.php'); $pdf->SetFont('DejaVu', '', 10, '', false);The following are three possible encodings that are possible.cp1250 (Central Europe) cp1251 (Cyrillic) cp1252 (Western Europe) cp1253 (Greek) cp1254 (Turkish) cp1255 (Hebrew) cp1257 (Baltic) cp1258 (Vietnamese) ... Read More

What is the difference between array_merge and array + array in PHP?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 08:10:00

204 Views

Both get the union of arrays, but array_merge() overwrites duplicate non_numeric keys. Let us now see an example of the array+array−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"]=> ... Read More

Return all dates between two dates in an array in PHP

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 08:04:44

3K+ Views

To return all dates between two dates, the code is as follows −Example Live DemoOutputThis will produce the following output−array(11) {    [0]=>    string(10) "10-11-2019"    [1]=>    string(10) "11-11-2019"    [2]=>    string(10) "12-11-2019"    [3]=>    string(10) "13-11-2019"    [4]=>    string(10) "14-11-2019"    [5]=>    string(10) "15-11-2019" ... Read More

Reset keys of array elements using PHP ?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 08:00:05

3K+ Views

To reset keys of array elements using PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−array(4) {    ["p"]=>    string(3) "150"    ["q"]=>    string(3) "100"    ["r"]=>    string(3) "120"    ["s"]=>    string(3) "110" } array(4) {    [0]=>    string(3) "150"    [1]=> ... Read More

How to remove the first character of string in PHP?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 07:53:32

2K+ Views

To remove the first character of a string in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output −Before removing the first character = Test After removing the first character = estExampleLet us now see another example Live DemoOutputThis will produce the following output−Before removing the first character ... Read More

Removing Array Element and Re-Indexing in PHP

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 07:49:34

266 Views

To remove an array element and re-index the array, 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 ... Read More

Advertisements