Posted By

cerxx on 01/14/19


Tagged

php-hacks


Versions (?)

Swap 2 array elements (PHP)


 / Published in: PHP
 

URL: https://expange.ru/e/%D0%9F%D0%BE%D0%BC%D0%B5%D0%BD%D1%8F%D1%82%D1%8C_%D0%BC%D0%B5%D1%81%D1%82%D0%B0%D0%BC%D0%B8_2_%D1%8D%D0%BB%D0%B5%D0%BC%D0%B5%D0%BD%D1%82%D0%B0_%D0%BC%D0%B0%D1%81%D1%81%D0%B8%D0%B2%D0%B0_(PHP)

The function changes the values ??of the elements of the array $ key and $ key2 in places @param $array - source array @param $key - key of array element @param $key2 - key 2 of array element @return bool true replacement occurred, false replacement did not occur

  1. function array_swap(array &$array, $key, $key2){
  2. if (isset($array[$key]) && isset($array[$key2])) {
  3. list($array[$key], $array[$key2]) = array($array[$key2], $array[$key]);
  4. return true;
  5. }
  6. return false;
  7. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: robertkwright on October 1, 2019

If you do not have enough time to write your academic papers. you should better hire the expert services https://expertwriter.net and forget about writing issues.

You need to login to post a comment.