php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #62299 array_two_key_swap wrong
Submitted: 2012-06-12 09:58 UTC Modified: 2012-06-22 21:57 UTC
From: bubrak at pinknet dot cz Assigned: salathe (profile)
Status: Closed Package: Arrays related
PHP Version: 5.3.13 OS: FreeBSD
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: bubrak at pinknet dot cz
New email:
PHP Version: OS:

 

 [2012-06-12 09:58 UTC] bubrak at pinknet dot cz
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;
} 
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-22 21:57 UTC] salathe@php.net
Your note was most likely deleted because on the note submission page [1] we 
explicitly ask note submitters not to add:

- References to other notes or authors
- Code collaboration or improvements 

The referenced note has also been deleted. [2]

[1] http://www.php.net/manual/add-note.php
[2] http://news.php.net/php.notes/188764
 [2012-06-22 21:57 UTC] salathe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: salathe
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 02:01:33 2025 UTC