How-to articles, tricks, and solutions about PHP

Laravel: getting a single value from a MySQL query

To get a single value from a MySQL query in Laravel, you can use the value method on a query builder instance.

Laravel: How to get last N entries from DB

You can use the latest method on a query builder instance to get the last N entries from the database.

Laravel: redirect from controller to named route with params in URL

In Laravel, you can redirect from a controller to a named route with URL parameters using the redirect() helper function.

Limit array to 5 items

You can use the "array_slice" function in PHP to limit an array to a specific number of items.

List all files in one directory PHP

To list all files in a directory using PHP, you can use the glob() function.

List of All Locales and Their Short Codes?

Here is a list of all the locales and their corresponding short codes that are available in PHP.

Location for session files in Apache/PHP

In Apache, the location for session files is determined by the session.save_path configuration directive in your php.ini file.

Lost connection to MySQL server at 'reading initial communication packet', system error: 0

This error message indicates that the client was unable to connect to the MySQL server.

Make var_dump look pretty

To make the output of var_dump() more readable, you can use the following approaches:

MassAssignmentException in Laravel

Here is an example of how a MassAssignmentException might be triggered in Laravel:

Max size of URL parameters in _GET

In PHP, the maximum size of the parameters in a GET request is determined by the server's configuration.

Measuring the distance between two coordinates in PHP

To calculate the distance between two coordinates in PHP, you can use the Haversine formula, which is a formula used to calculate the distance between two points on a sphere based on their longitudes and latitudes.

Merge PDF files with PHP

There are several ways to merge PDF files using PHP.

Merging cells in Excel by rows and columns together using PHPExcel

To merge cells in Excel using PHPExcel, you can use the mergeCells() method.

Message: Trying to access array offset on value of type null

This error message is indicating that you are trying to access an array offset (i.e., an element of an array) but the value being accessed is null.

Most efficient way to search for object in an array by a specific property's value

In PHP, you can use the built-in function array_filter() to filter the array by a specific property's value.

Multiple excerpt lengths in wordpress

In WordPress, the length of the excerpt (the summary text displayed on the homepage or archive pages) can be controlled by the theme or by a plugin.

Multiple Inheritance in PHP

In PHP, multiple inheritance is not supported in the traditional sense, where a class can inherit from multiple classes.

MySQL - How to select rows where value is in array?

You can use the IN operator to select rows where the value is in an array.

MySQL Check if username and password matches in Database

To check if a given username and password match those stored in a MySQL database, you can use a SQL SELECT statement with a WHERE clause.

MySQL Database won't start in XAMPP Manager-osx

There could be a number of reasons why your MySQL database isn't starting in XAMPP on macOS.

MySQL Great Circle Distance (Haversine formula)

The Haversine formula is a mathematical formula that can be used to calculate the great-circle distance between two points on a sphere, such as the Earth.

Mysql password expired. Can't connect

If your MySQL password has expired and you can't connect, you will need to reset the password.

MySQL query to get column names?

To get the column names of a table in MySQL, you can use the SHOW COLUMNS FROM command.

MySQL server has gone away - in exactly 60 seconds

The "MySQL server has gone away" error message typically indicates that the connection to the MySQL server was lost.