php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60426 array_keys convert keys type
Submitted: 2011-12-01 14:26 UTC Modified: 2011-12-01 14:50 UTC
From: damiannohales at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: damiannohales at gmail dot com
New email:
PHP Version: OS:

 

 [2011-12-01 14:26 UTC] damiannohales at gmail dot com
Description:
------------
I noticed when I extract the keys of an array using array_keys, if a key is an string with a number, on the resulting array from the array_keys execution I get an integer for this key instead of a string.

My version of PHP is 5.3.5-1ubuntu7.3.

Regards!

Test script:
---------------
$a = array(
	'1' => 'apple',
	'2' => 'banana',
	'3' => 'orange',
	'4' => 'stawberry',
);
$keys = array_keys($a);
echo gettype( $keys[0] );

Expected result:
----------------
Output:

string

Actual result:
--------------
Output

integer

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-01 14:50 UTC] laruence@php.net
-Status: Open +Status: Bogus
 [2011-12-01 14:50 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

" A key may be either an integer or a string. If a key is the standard 
representation of an integer, it will be interpreted as such (i.e. "8" will be 
interpreted as 8, while "08" will be interpreted as "08"). " 
http://www.php.net/manual/en/language.types.array.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 17:01:34 2025 UTC