0

This is my array:

<?php
$sku = ['HH017','HH018','HH005','HH010','20OZHHTUMBLER',
        '30OZTUMBLER2','HH006','HH-05'];

$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

0
$sequencedValues = [];

$sku = ['HH017','HH018','HH005','HH010','20OZHHTUMBLER',
        '30OZTUMBLER2','HH006','HH-05'];

$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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.