note 81913 added to function.array-combine
| From: | MikeJean at osu1 dot php dot net | Date: | Wed, 19 Mar 2008 05:59:04 +0000 |
| Subject: | note 81913 added to function.array-combine | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137194@lists.php.net to get a copy of this message | ||
Khaly's PHP4 code below does not work correctly in all cases. Consider when your array consists
of floats:
<?php
$okay = array(0, 10, 20, 30);
$not_okay = array(0, 0.5, 1, 1.5);
$foo = array_combine($okay, $okay);
$bar = array_combine($not_okay, $not_okay);
/*
Results:
$foo = {
[0]=> int(0)
[10]=> int(10)
[20]=> int(20)
[30]=> int(30)
}
$bar = {
[0]=> float(0.5)
[1]=> float(1.5)
}
*/
?>
What can you do? In my case, I was just zipping up some select-box options, so I converted
everything in my floats to strings.
----
Server IP: 216.235.15.211
Probable Submitter: 24.79.243.190
----
Manual Page -- http://www.php.net/manual/en/function.array-combine.php
Edit -- https://master.php.net/note/edit/81913
Del: integrated -- https://master.php.net/note/delete/81913/integrated
Del: useless -- https://master.php.net/note/delete/81913/useless
Del: bad code -- https://master.php.net/note/delete/81913/bad+code
Del: spam -- https://master.php.net/note/delete/81913/spam
Del: non-english -- https://master.php.net/note/delete/81913/non-english
Del: in docs -- https://master.php.net/note/delete/81913/in+docs
Del: other reasons-- https://master.php.net/note/delete/81913
Reject -- https://master.php.net/note/reject/81913
Search -- https://master.php.net/manage/user-notes.php