ItSolutionStuff.com

How to Get Minimum Key Value of Array in PHP?

By Hardik Savani • May 14, 2024
PHP

Sometimes, you need to get minimum key value of your array but you try to get with loop and any function etc, but in bellow example you can see we can get smallest key value from our php array by using min() and array_keys(). So, let's try to use in your code this way:

index.php

<!DOCTYPE html>

<html>

<body>

<?php

$myArray = ['2'=>'Hey','4'=>'Hello','1'=>'Hi','3'=>'GH'];

$new_key = min(array_keys($myArray));

$new_val = $myArray[$new_key];

print_r($new_val);

?>

</body>

</html>

Output:

Hi

I hope it can help you...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Check Current PHP Version in Ubuntu?

Read Now →

How to Convert String to Date in PHP?

Read Now →

PHP CURL Post Request with Parameters Example

Read Now →

PHP Dropzone Display Existing Files from Server Example

Read Now →

PHP Import Excel File into MySQL Database Tutorial

Read Now →

How to Get File Name without Extension in PHP?

Read Now →

PHP Check Word Exist in String or Not Example

Read Now →

How to Get a Current Page URL in PHP?

Read Now →

How to Get the File Size in PHP?

Read Now →

How to Convert Array Values to Lowercase in PHP?

Read Now →

MySQL Query to Get Current Month Data Example

Read Now →

How to Find Day Name from Specific Date in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →