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

  • Home
  • SEARCH
  • 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 7719981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:33:01+00:00 2026-06-01T03:33:01+00:00

$array = array (0.1 => ‘a’, 0.2 => ‘b’); echo count ($array); It overwrites

  • 0

$array = array (0.1 => 'a', 0.2 => 'b');
echo count ($array);

It overwrites first array element by second, just because, I used float with 0.

And hence output of above code is 1, instead of 2.

Why PHP round array index down to 0 ?

  • 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-06-01T03:33:02+00:00Added an answer on June 1, 2026 at 3:33 am

    The array keys are interpreted as numeric, but numeric keys must be integers, Therefore, both float values are cast (truncated) to integer zero and 0.2 overwrites 0.1.

    var_dump($array);
    array(1) {
      [0]=>
      string(1) "b"
    }
    

    Make the array keys strings if you want to use non integer values:

    $array = array ("0.1" => 'a', "0.2" => 'b');
    echo count($array);
    // 2
    
    array(2) {
      ["0.1"]=>
      string(1) "a"
      ["0.2"]=>
      string(1) "b"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First array list:- ArrayList<Object> list1; Second array list:- ArrayList<Object> list2; Suppose I have filled
# array C:\> (1,2,3).count 3 C:\> (1,2,3 | measure).count 3 # hashtable C:\> @{1=1;
array 1703 => float 15916.19738 5129 => float 11799.15419 33 => float 11173.49945 1914
array[10]={2,3424,4234,42,234,234,23423,123,342,3} In this array, how do I find the first five biggest numbers and
array: [1,2,1,1,2,2,2,1,1,1,1,1] indexes: [0,3,5,1] output: [1,1,2,2]
array = [1,2,3,{:name => Peter}, hello] array.each do |element| # it can be inject,
Array $imagelist: Array ( [additional] => Array ( [count] => 2 [image] => Array
Array $data2 is used for making charts, it contains product names of my company.
Array#find_index allows you to find the index of the first item that either is
Array.Copy and Buffer.BlockCopy both do the same thing, but BlockCopy is aimed at fast

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.