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 sequnce to show my data in this format.

Please advice.

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, privacy policy and cookie policy

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