How-to articles, tricks, and solutions about PHP

How do you enable mod_rewrite on any OS?

To enable mod_rewrite on a PHP server, you will need to make sure that the Apache mod_rewrite module is installed and enabled.

How do you get php working on Mac OS X?

To get PHP working on Mac OS X, you can follow these steps:

How do you reindex an array in PHP but with indexes starting from 1?

You can use the array_values function to get a new array with the values of the original array, and then use the array_combine function to create an array using the new values and an indexed array of keys starting from 1:

How do you remove an array element in a foreach loop?

It is generally not recommended to remove array elements while iterating over the array using a foreach loop, because the loop will behave unexpectedly when elements are removed.

How I can put composite keys in models in Laravel 5?

In Laravel 5, you can specify a composite key on a model by defining a protected $primaryKey property on the model and setting it to an array of the column names that make up the primary key.

How to "flatten" a multi-dimensional array to simple one in PHP?

In PHP, you can use the "array_reduce" function to flatten a multi-dimensional array.

How to access an application parameters from a service?

In PHP, you can access application parameters from a service by injecting the ParameterBag object into the service class constructor.

How to access mysql result set data with a foreach loop

To access MySQL result set data with a foreach loop, you can use a loop like the following:

How to access the php.ini from cPanel?

To access the php.ini file from cPanel, you can follow these steps:

How to add 5 minutes to current datetime on php < 5.3

You can use the strtotime function in PHP to add a certain number of minutes to a date and time.

How to add a print button to a web page

To add a print button to a web page using PHP, you can use the following steps:

How to add an ORDER BY clause using CodeIgniter's Active Record methods?

To add an ORDER BY clause to a query using CodeIgniter's Active Record class, you can use the order_by() method.

How to Add Elements to an Empty Array in PHP

In this tutorial, we display and describe the most flexible ways to add elements to an empty array. Follow the steps and you will manage that easily.

How to add http:// if it doesn't exist in the URL

You can use the following code snippet to add "http://" to the beginning of a URL if it doesn't already exist:

How to add property to object in PHP >= 5.3 strict mode without generating error

In PHP >= 5.3, you can use the Object::$strictProperties property to enable or disable strict property checking for an object.

How to add text to an image with PHP GD library

Here is an example of how you can add text to an image using the PHP GD library:

How to alias a table in Laravel Eloquent queries (or using Query Builder)?

To alias a table in a Laravel Eloquent query, you can use the as method on a DB facade.

How to Append an Array to Another in PHP

While working with PHP, developers wonder how to append one array to another. This snippet is dedicated to the exploration of functions that help to do it.

How to assign an array within a smarty template file?

In a Smarty template file, you can assign an array to a variable using the assign function.

How to Automatically Start a Download in PHP?

To automatically start a download in PHP, you can use the header() function to send the appropriate headers to the browser indicating that a file download should begin.

How to benchmark efficiency of PHP script

There are several ways to benchmark the efficiency of a PHP script, including:

How to build a RESTful API?

To build a RESTful API in PHP, you can use a framework such as Laravel or CodeIgniter, or you can build the API from scratch using core PHP.

How to Calculate the Difference between Two Dates Using PHP?

On this page, you have an opportunity to get comprehensive information on how to calculate the difference between two dates with the help of PHP.

How to call a function from a string stored in a variable?

To call a function from a string stored in a variable in PHP, you can use the call_user_func() function.

How to call a php script/function on a html button click?

To call a PHP script or function on a HTML button click, you can use JavaScript to send an HTTP request to the server when the button is clicked.