-3

I am pulling through variations(options) of a product. Each variation/option has a different name/code and sometimes it contains a mixture of numbers and letters.

I would like to know if there is a way I can sort this in a neat way.

Please see picture attach of how the variations are currently listed.

Thanks in advance!

enter image description here

Juan J
  • 413
  • 6
  • 12

1 Answers1

3

A sort() can do that for you. Here's an example from the PHP page doing pretty much the same thing you are trying to do:

$fruits = array(
    "Orange1", "orange2", "Orange3", "orange20"
);

sort($fruits, SORT_NATURAL | SORT_FLAG_CASE);

foreach ($fruits as $key => $val) {
    echo "fruits[" . $key . "] = " . $val . "\n";
}

This example will output:

fruits[0] = Orange1
fruits[1] = orange2
fruits[2] = Orange3
fruits[3] = orange20
I.Dzinka
  • 44
  • 1
  • 4