How-to articles, tricks, and solutions about PHP

Get Category name from Post ID

To get the category name from a post ID in PHP, 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:

Change Timezone in Lumen or Laravel 5

In Laravel or Lumen, you can set the timezone for your application by setting the timezone option in your config/app.php configuration file.

WAMP Server ERROR "Forbidden You don't have permission to access /phpmyadmin/ on this server."

It sounds like you are trying to access the PHPMyAdmin interface on your WAMP server and are receiving a "Forbidden" error message.

How to install PHP intl extension in Ubuntu 14.04

To install the PHP intl extension on Ubuntu 14.04, follow these steps:

Laravel Check If Related Model Exists

In Laravel, you can use the exists method on a relationship to check if it has any related models.

How to get Current Timestamp from Carbon in Laravel 5

You can use the now() method from the Carbon class to get the current timestamp in Laravel.

Why shouldn't I use mysql_* functions in PHP?

The mysql_* functions in PHP are deprecated, meaning that they are no longer recommended for use and will likely be removed in a future version of PHP.

Curl error 60, SSL certificate issue: self signed certificate in certificate chain

This error message appears when curl is unable to verify the SSL/TLS certificate presented by the server.

isset PHP isset($_GET['something']) ? $_GET['something'] : ''

In PHP, isset() is a function that determines whether a variable is set and is not NULL.

Secure hash and salt for PHP passwords

To securely hash and salt passwords in PHP, you can use the password_hash function.

Unicode character in PHP string

You can use Unicode characters in a PHP string by including the character directly in the string, or by using the \u escape sequence followed by the Unicode code point of the character in hexadecimal.

How Can I Remove “public/index.php” in the URL Generated Laravel?

To remove "public/index.php" from the URL in a Laravel application, you can use the built-in PHP web server or set up a web server with Apache or Nginx.

PHP Composer update "cannot allocate memory" error (using Laravel 4)

This error can occur when the composer process is trying to allocate more memory than is available to it.

Tell Composer to use Different PHP Version

To use a specific version of PHP with Composer, you can specify the version you want to use in the config section of your composer.json file.

PHP/MySQL insert row then get 'id'

To insert a row into a MySQL database table and get the id of the inserted row in PHP, you can use the mysqli_insert_id() function.

Commands out of sync; you can't run this command now

The "Commands out of sync; you can't run this command now" error in PHP usually occurs when you have called a MySQL function in an incorrect order.

Which is a better way to check if an array has more than one element?

There are several ways to check if an array has more than one element in PHP.

Laravel says "Route not defined"

There could be several reasons why you are seeing this error message in Laravel.

Get custom product attributes in Woocommerce

To retrieve custom product attributes in WooCommerce, you can use the get_post_meta() function.

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.

How to Make Laravel Eloquent "IN" Query?

You can use the whereIn method on a query builder instance to create an "IN" clause for a given column and values.

How do I write to the console from a Laravel Controller?

You can use the Log facade to write to the console from a Laravel controller.

Laravel orderBy on a relationship

In Laravel, you can use the orderBy method on a relationship to sort the results of the relationship by a given column.