Quantcast
Channel: User Bijan - Stack Overflow
Viewing all articles
Browse latest Browse all 97

Sort an array by another array of value priorities which may have more values than the original input array [duplicate]

$
0
0

I have a comma separated string/array:

$input = "facebook,steam,tumblr,email,instagram,twitter,twitch,youtube,pinterest,amazon,disqus";$input = explode(",", $input);

that I want to be ordered based on another array:

$order = "email,facebook,instagram,twitter,twitch,youtube,steam,pinterest,tumblr,amazon,disqus";$order = explode(",", $order);

$input will always contain a value that is in $order and I want it to be sorted based on the order that it comes in $order. This is a bit tricky because $input will only contain a subset of values from $order.

For example, an input of twitter,twitch,email,facebook would return email,facebook,twitter,twitch


I have already found This Solution but it does not apply because I am not dealing with keys in my array.


Viewing all articles
Browse latest Browse all 97

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>