Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7612099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:49:31+00:00 2026-05-31T01:49:31+00:00

Using print_r returns the following array: Array ( [5358] => red [1] => green

  • 0

Using print_r returns the following array:

Array ( [5358] => red [1] => green [503] => blue )

How can I access the smallest numbered element in the array, in this case “green”?

The values will change but I just need the smallest valued element.

Using echo min($myArray); will return “red”. There must be something I’m missing here. Using usort or other “advanced” ways to first sort and then extract the largest value can’t be the only solution here… right!?!

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:49:32+00:00Added an answer on May 31, 2026 at 1:49 am

    min() looks in values, not in keys. array_keys() will do the trick

    echo min(array_keys($myArray)); 
    

    will do the trick. To get its value, try

    echo $myArray[min(array_keys($myArray))];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code to populate an array: $number = count ($quantitys);
I try to use amazon API using PHP. If I use print_r($parsed_xml->Items->Item->ItemAttributes) it show
I'm using the following preg_match to get the [title] tag of a webpage. //
I'm looking for the correct way of using wp_get_attachment_image(). The following code: <?php $args
I want to count some rows in my database and I'm using the following
UPDATE 4: print_r( $data ); returns the data I posted in the original question,
I have the following code. PHP side: <?php print_r($_POST); print_r($_GET); die(); ?> In JavaScript:
I'm using the following code to try to read the results of a df
Hi I'm trying to convert the XML file into associative array by using the
We are using following code for setters. if (is_numeric($id)) { global $db; $product =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.