2

I have size attribute (S,M,L,XL,2XL). I want to sort it by this way, now its showing like (2XL,S,M,L,XL). How can I sort it? I am using following code:

$products_grid_ret = array();
$temparray = array();
foreach($products_grid as $key => $product) {
  $temparray[$key] = array();
  foreach($product['attributes'] as $att) {
    $temparray[$key][] = $att['value'];
  }
}
$sorted_array = $temparray;
sort($sorted_array);
foreach($sorted_array as $atts) {
  $key = array_search($atts, $temparray);
  $products_grid_ret[$key] = $products_grid[$key];
}
return $products_grid_ret;
  • I solved it myself.... – user9748 Apr 24 '15 at 6:45
  • 1
    If you have time - put your solution here. Can be helpful for another people. – zhartaunik Apr 24 '15 at 7:48
0
foreach($product['attributes'] as $att) {
    $temparray[$key][] = $att['option_id'];
}
|improve this answer|||||
  • did this fix the issue for you? then feel free to accept the answer – David Manners May 1 '15 at 6:54

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.