Answers.Body: <p>Try removing the quotes on 2nd/3rd arguments:</p>
  
  <p><code>{% set rides = furniture|multisort(furniture['price'],[SORT_DESC],[SORT_REGULAR]) %}</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-17T15:18:30.437Z
Answers.Text: Yes that worked although my syntax was wrong so this worked: {% set sorted = furniture|multisort(['price'],[SORT_ASC],[SORT_REGULAR]) %} Thanks very much for your help!!!!!
Answers.UserDisplayName: cannon303
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-17T14:20:28.227Z
Answers.LastActivityDate: 2019-07-17T14:20:28.227Z
Answers.UserDisplayName: dmatthams
Body: <p>Hi hoping for a quick resolution on this as a lot of scripting relies upon it. I have an array:</p>
  
  <pre><code>{% set furniture = [
       {
           'name': 'chair',
           'price': '100'
       },
       {
           'name': 'bench',
           'price': '500'
       }
     ]
  %}
  </code></pre>
  
  <p>and I'm trying to sort it by price:</p>
  
  <pre><code>{% set sorted = furniture|multisort(['price'],['SORT_DESC'],['SORT_REGULAR']) %}
  </code></pre>
  
  <p>but all I get is this error:</p>
  
  <p>array_multisort(): Argument #2 is expected to be an array or a sort flag.</p>
  
  <p>I've also tried:</p>
  
  <pre><code>{% set rides = furniture|multisort(furniture['price'],['SORT_DESC'],['SORT_REGULAR']) %}
  </code></pre>
  
  <p>but then I get the error:</p>
  
  <p>Key "price" for array with keys "0, 1" does not exist.</p>
  
  <p>I've kind of run out of ideas as to how to tackle it. Thanks.</p>
  
Tags: <filter><array><sort><multisort>
Title: Help with correct syntax regarding multisort please
ThreadText: # Help with correct syntax regarding multisort please
  
  (Asked by: username_0 on 2019-07-17)
  
  Hi hoping for a quick resolution on this as a lot of scripting relies upon it. I have an array:
  
  ```
  {% set furniture = [
       {
           'name': 'chair',
           'price': '100'
       },
       {
           'name': 'bench',
           'price': '500'
       }
     ]
  %}
  
  ```
  
  and I'm trying to sort it by price:
  
  ```
  {% set sorted = furniture|multisort(['price'],['SORT_DESC'],['SORT_REGULAR']) %}
  
  ```
  
  but all I get is this error:
  
  array\_multisort(): Argument #2 is expected to be an array or a sort flag.
  
  I've also tried:
  
  ```
  {% set rides = furniture|multisort(furniture['price'],['SORT_DESC'],['SORT_REGULAR']) %}
  
  ```
  
  but then I get the error:
  
  Key "price" for array with keys "0, 1" does not exist.
  
  I've kind of run out of ideas as to how to tackle it. Thanks.
  
  **Tags:** filter, array, sort, multisort
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-07-17. Score: 1 | Accepted answer
  
  Try removing the quotes on 2nd/3rd arguments:
  
  `{% set rides = furniture|multisort(furniture['price'],[SORT_DESC],[SORT_REGULAR]) %}`
  
  > **Comments:**
  > **username_0**: Yes that worked although my syntax was wrong so this worked: {% set sorted = furniture|multisort(['price'],[SORT_ASC],[SORT_REGULAR]) %} Thanks very much for your help!!!!!  
  
  ---
  
  