This is my array:

$sku = ['HH017','HH018','HH005','HH010','20OZHHTUMBLER',

$sequence = ['HH005','HH010','HH006','20OZHHTUMBLER',...];

print_r(sort($sku, $sequence));


I want to arrange that data of $sku in $sequence format. I want to show the first 4 numbers from $sku, as mentioned in $sequence and then the remaining numbers will be shown after these 4 numbers.

How can I arrange the sequence to show my data in this format?

Please advice.

1 Answer 1

$sequencedValues = [];

$sku = ['HH017','HH018','HH005','HH010','20OZHHTUMBLER',

$sequence = ['HH005','HH010','HH006','20OZHHTUMBLER'];

foreach ($sequence as $value) {
    if (in_array($value, $sku)) {
        $sequencedValues[] = $value;
        unset($sku[array_search($value, $sku)];

$sequencedValues = array_merge($sequencedValues, $sku);

Probably a more efficient way to do it but that should work. This isn't a Magento specific question so shouldn't really be in the Magento stack exchange.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.