Uncategorized

Bringing an array element to the top of the Array.

By March 7, 2020 No Comments

What to do when you want a specific array element to bring to the top of the array? One use case is let’s say for a countries array you want to bring US to the top and then the rest.

Here’s what I do.

I pull all the countries except for US, easy!

Next, I pull only the US.

Then I use array_merge to combine both the arrays and then the US comes to the top.

I’m sure there must be better ways to do this but this helped.