Doc #62299 [NEW]: array_two_key_swap wrong
From: bubrak at pinknet dot cz
Operating system: FreeBSD
PHP version: 5.3.13
Package: Arrays related
Bug Type: Documentation Problem
Bug description:array_two_key_swap wrong
Description:
------------
---
From manual page: http://www.php.net/function.array
---
User note bellow array() manual dated "10-Oct-2009 01:39" showing function
array_two_key_swap is misleading and will cost other users time, as it is
not working in the way it says - tranferring array[k1][k2] into
array[k2][k1], it only works for integer k2 keys which is wrong. I entered
simplier function as a new note but it was deleted. I don't understand why
misleading code is kept online with PHP manual and proper fix is deleted.
Test script:
---------------
It is obvious. No need to show it here.
Proper code is here:
<?php
function array_two_key_swap( $a ) {
$ra = array();
while (list($k1,$v1) = each ($a)) {
while (list($k2,$v2) = each ($v1)) {
$ra[$k2][$k1]=$v2;
}
}
return $ra;
}
?>
--
Edit bug report at https://bugs.php.net/bug.php?id=62299&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62299&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62299&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62299&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=62299&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62299&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=62299&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=62299&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=62299&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=62299&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=62299&r=support
Expected behavior: https://bugs.php.net/fix.php?id=62299&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=62299&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=62299&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=62299&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62299&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62299&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=62299&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=62299&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=62299&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=62299&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=62299&r=mysqlcfg
Thread (2 messages)
- bubrak at pinknet dot cz