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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 11:01:34 2024 UTC