Req #80746 [Opn]: shuffle really should maintain key=>value relation

From: Date: Wed, 24 Nov 2021 12:25:42 +0000
Subject: Req #80746 [Opn]: shuffle really should maintain key=>value relation
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237963@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80746&edit=1

 ID:                 80746
 User updated by:    szfjozsef at gmail dot com
 Reported by:        szfjozsef at gmail dot com
 Summary:            shuffle really should maintain key=>value relation
 Status:             Open
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   Irrelevant
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

> Citation needed. :)

Well, this is not really possible, but if you accept as citation, please make a Google search, this
reveals how many people actually wrote some kind of function to restore the original key-value
relation.

Yes, it is a long and inefficient function... A lot of processor time is needed to do something,
that in the first place already is available in the shuffle() internal function.

I strongly think, not maintaining the key=>value associations (in all other PHP functions also)
is a waste of time and resources. There is no reason to do this, since there are no benefits of
this.

There is room for a second parameter, eg. $maintainKeys = false. Simple and clean, and it does not
break old code. Of course, for all functions that destroy the keys when processing arrays...


Previous Comments:
------------------------------------------------------------------------
[2021-11-22 17:58:15] cmb@php.net

> People around the world are struggling by using the shuffle()
> function.

Citation needed. :)

> Have to write cumbersome, long, inefficient functions just to
> restore the key=>value associations.

<https://www.php.net/manual/en/function.shuffle.php#94697>
does
neither look cumbersome nor long – but might be inefficient.

------------------------------------------------------------------------
[2021-02-13 16:17:10] szfjozsef at gmail dot com

Description:
------------
---
From manual page: https://php.net/function.shuffle
---
People around the world are struggling by using the shuffle() function. There is absolutely no
reason to reset the keys to 0,1,2,3 when shuffling the array.
Please make shuffle() maintain the keys.

Expected result:
----------------
call shuffle() and move on.

Actual result:
--------------
Have to write cumbersome, long, inefficient functions just to restore the key=>value
associations.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80746&edit=1


Thread (3 messages)

« previous php.bugs (#237963) next »