|  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
 [2011-12-01 14:26 UTC] damiannohales at gmail dot com
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.


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

Expected result:


Actual result:



Add a Patch

Pull Requests

Add a Pull Request


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

" 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"). "
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Feb 25 00:01:23 2021 UTC