Posted By

cerxx on 01/14/19



Versions (?)

Swap 2 array elements (PHP)

 / Published in: 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  


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 and forget about writing issues.

You need to login to post a comment.