ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

PHP function that shuffles an associative array while preserving the key-value pairs | array_keys()

PHP

AssociativeArray

ShuffleAssociativeArray

Автор: PHP scripts 2020

Загружено: 2020-04-25

Просмотров: 369

Описание: In this video, we are going to learn how to shuffle an associative array while preserving the key-value pairs. Let’s say we have two arrays: an indexed array and an associative array.

If we want to shuffle the indexed array, we can use the built-in array function shuffle() with great results. But if we want to shuffle the associative array while preserving the key-value pairs, there isn’t a built-in function to do that. If we use the shuffle() function to shuffle the associative array, the values of the associative array will be shuffled but the original named keys will be removed and replaced with indexes.

So, we have to create a custom function. We will call this function shuffle_assoc_arr(). Its argument is an associative array and its output is the same associative array but shuffled and with the key-value pairs preserved.

First, we declare the array that is going to store the key-value pairs of the original associative array, arranged in a new random order. Then, we extract the keys of the associative array and store them in an indexed array. The keys of the original associative array are the values of the new indexed array. We shuffle the new indexed array of keys, build up the new associative array and, finally, return it.

/* *** *** *** *** *** *** *** */

If you want to watch videos about mathematics and physics, you can subscribe to my second YouTube channel: https://www.youtube.com/@Sohcahtoa160....

You can support my work by becoming a patron:   / sohcahtoa1609  
Follow Sohcahtoa1609 on Twitter:   / sohcahtoa1609  
Like Sohcahtoa1609 on Facebook:   / sohcahtoa1609  
Follow Sohcahtoa1609 on Instagram:   / sohcahtoa1609  

Disclaimer: this video is meant to be a proof of concept.

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
PHP function that shuffles an associative array while preserving the key-value pairs | array_keys()

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]