Answer by mickmackusa for Shift one value of array values to the beginning
I'm not sure if "more beautiful" means you want a one-liner, but here are two more concise ways to perform the task:*note, this doesn't validate the $value as being one of the element values -- if this...
View ArticleAnswer by Your Common Sense for Shift one value of array values to the beginning
I hate hardcoded solutions and prefer generalized ones. You never know when your array will get a 4th element and break all the application.So a generalized solution would be likeget a key for the...
View ArticleAnswer by Roland Illig for Shift one value of array values to the beginning
Yes, for three array elements you can write:$arr = [ ($value - 1) % 3 + 1, ($value + 0) % 3 + 1, ($value + 1) % 3 + 1];The main ingredient here is the $value modulo 3 expression. The above code...
View ArticleAnswer by Sᴀᴍ Onᴇᴌᴀ for Shift one value of array values to the beginning
Is there a shorter and more beautiful way of doing that?shorter: yesmore beautiful: well, that sounds subjective... you can be the judge of the approaches below.One approach would be to take off the...
View ArticleShift one value of array values to the beginning
Given an integer $value in the range of 1, 2, 3, I want to get an array that starts with $value and proceeds with the remaining two integers from above in arbitrary order. The best I could think of was...
View Article