An introduction to WeakMap in PHP (6 examples)
Updated: Feb 20, 2024
Introduction PHP introduced WeakMap in version 8.0, making a significant move towards more efficient memory management for applications. A WeakMap allows us to associate values to objects in a way that doesn’t prevent those......
Type Declarations for Class Properties in PHP (5 examples)
Updated: Feb 20, 2024
Introduction Type declarations, also referred to as type hints, allow developers to specify the expected data type of an argument in a function declaration, a return type from a function, or, since the release of PHP 7.4, the data type......
Static Return Type in PHP: Explained with examples
Updated: Feb 20, 2024
Introduction In the ever-evolving world of PHP, the introduction of static return types in PHP 8.0 marks a significant milestone towards a more robust and type-safe programming style. This feature provides more flexibility and......
PHP: Using DocBlock comments to annotate variables
Updated: Feb 20, 2024
Introduction When it comes to making your code more understandable and maintainable, proper documentation can never be overemphasized. PHP, being one of the most popular server-side programming languages, supports a variety of ways to......
PHP: How to ping a server/website and get the response time
Updated: Feb 19, 2024
Introduction Pinging a server is a network utility command (ping) that checks if a host is reachable. It is a diagnostic tool used to test the connectivity and measure the round-trip time for messages sent from the originating host to......
PHP: 3 Ways to Get City/Country from IP Address
Updated: Feb 19, 2024
Overview Discovering the geographical location of a user based on their IP address can be very useful for various web applications. Be it for localizing content, implementing geo-restrictions, or simply gathering analytics, PHP offers......
PHP: How to find the mode(s) of an array (4 examples)
Updated: Feb 19, 2024
Introduction Finding the mode of an array — the value(s) that appears most frequently — can be a common task in data processing and analytics with PHP. Unlike calculating the mean (average) or the median, finding the mode might......
PHP: Calculate standard deviation & variance of an array
Updated: Feb 19, 2024
Introduction Understanding how to calculate the standard deviation and variance of an array in PHP is crucial for any developer working with datasets, as it helps in understanding the dispersion or spread of the dataset. This tutorial......
PHP: 3 Ways to Get N Random Elements from an Array
Updated: Feb 19, 2024
Overview Getting random elements from an array is a common task in many PHP applications. Whether you’re building a quiz app that selects random questions, implementing a feature to display random testimonials on a website, or......
PHP: Find and download photos by keyword from Unsplash API
Updated: Feb 14, 2024
Introduction In this tutorial, we’ll dive into how to use the Unsplash API with PHP to search for photos by keyword and download them. Unsplash provides high-quality free images, shared by a community of photographers. Their API......
Laravel + Faker: Generate user with email and gender based on name
Updated: Feb 14, 2024
Introduction When developing applications, especially in the testing phase, there’s often a need for generating dummy data. Laravel, a robust PHP framework, provides seamless integration with Faker, a PHP library for creating......
Laravel: Rendering CSV data in an HTML table
Updated: Feb 14, 2024
Overview In this tutorial, we will explore how to render CSV data within an HTML table using Laravel, a popular PHP framework known for its simplicity and elegance in web development. Whether you’re dealing with data exports,......