Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
change a php array element location?
ok i want to do this
$ar = ['a'=>5,'b'=>6,'c'=>7];//key a might occur anywhere in the array so
if(isset($ar['a']))
//insert code so $ar would be
$ar = ['b'=>6,'c'=>7,'a'=>5];
thanks
1 Answer
- Anonymous8 years agoFavorite Answer
$ar = array('a'=>5,'b'=>6,'c'=>7);
if (isset($ar['a'])) {
$temp = array('a' => $ar['a']);
unset($ar['a']);
$ar = array_merge($ar, $temp);
}
Here's one ugly solution. I'm not sure why you would want to do this though.
Check out another solution below.