php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36784 array_search() is not working
Submitted: 2006-03-18 19:03 UTC Modified: 2006-03-18 22:39 UTC
From: gorivo at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.4.2 OS: Windows XP
Private report: No CVE-ID: None
 [2006-03-18 19:03 UTC] gorivo at gmail dot com
Description:
------------
It seems array_search() is not working...

Reproduce code:
---------------
URL to PHP code: 
http://www.huntexpired.com/gorivo/array_search.phps

Expected result:
----------------
504 ( the array key of "0e0" )

Actual result:
--------------
0 ( FALSE )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-18 20:32 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2006-03-18 21:18 UTC] gorivo at gmail dot com
The source code is almost size of 1 mb. The main size of it, is occupied by huge array of 46656 keys. I can't shorten it because if I edit array's entries the script sometimes is working! It is very strange behavior.

URL to working PHP script:
http://www.huntexpired.com/gorivo/array_search.php

URL to PHP code:
http://www.huntexpired.com/gorivo/array_search.phps
 [2006-03-18 21:25 UTC] tony2001@php.net
So how (and why) do you want us to debug it when the script is 1mb long and its expected result is unknown?
 [2006-03-18 22:12 UTC] gorivo at gmail dot com
Ok, Tony, I found a way how to shorten my code. Here it is:

<?php

for($x=0; $x!=10; $x++)
	$symbols[] = $x;

for($x='a'; $x!='aa'; $x++)
	$symbols[] = $x;

foreach( $symbols as $v1 )
foreach( $symbols as $v2 )
foreach( $symbols as $v3 )
	$arr[] = $v1.$v2.$v3;

# WORKS!: (returns 13368 as expected)
echo 'key for "abc": '.array_search('abc', $arr).'<br />';
# DOESN`T WORK!: (should return 504, but doesn't)
echo 'key for "0e0": '.array_search('0e0', $arr).'<br />';

?>

The script above generates all possible 3-char combinations from numbers and letters (from 000 to zzz) and saves them to $arr. Everything is ok, except that array_search is not working for values from '0e0' to '0e9'. That's the problem. I hope you understood me :)

Working script:
http://www.huntexpired.com/gorivo/array_search.php

Source code:
http://www.huntexpired.com/gorivo/array_search.phps
 [2006-03-18 22:22 UTC] johannes@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

The strings like "0e0" are interpreted as numeric values, 
0 * 10^0, see 
http://php.net/manual/en/language.types.string.php#language.types.string.conversion
 [2006-03-18 22:39 UTC] gorivo at gmail dot com
Thank you, Johannes, for solving my problem! :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 16:01:31 2024 UTC