M
M
m4f12019-12-05 00:32:45
PHP
m4f1, 2019-12-05 00:32:45

How to sort array values ​​alphabetically in php?

I have an array that needs to be sorted alphabetically wa_dump($filters):

Array
(
  0 => Array
  (
    id => '675'
    parent_id => NULL
    code => 'tsvet1'
    status => 'public'
    name => 'Цвет'
    type => 'color'
    selectable => '1'
    multiple => '1'
    count => '25'
    values => Array
    (
      27 => shopColorValue object
      {
        shopColorValuecode => '0'
        shopColorValuevalue => 'чёрный'
        shopColorValueid => '27'
        shopColorValuesort => '1'
        shopColorValue_data => NULL
        feature_id => '675'
      }
      34 => shopColorValue object
      {
        shopColorValuecode => '255'
        shopColorValuevalue => 'синий'
        shopColorValueid => '34'
        shopColorValuesort => '9'
        shopColorValue_data => NULL
        feature_id => '675'
      }
      44 => shopColorValue object
      {
        shopColorValuecode => '13209'
        shopColorValuevalue => 'переливающийся'
        shopColorValueid => '44'
        shopColorValuesort => '15'
        shopColorValue_data => NULL
        feature_id => '675'
      }
      54 => shopColorValue object
      {
        shopColorValuecode => '49151'
        shopColorValuevalue => 'голубой'
        shopColorValueid => '54'
        shopColorValuesort => '10'
        shopColorValue_data => NULL
        feature_id => '675'
      }
      48 => shopColorValue object
      {
        shopColorValuecode => '3200456'
        shopColorValuevalue => 'бирюзовый'
        shopColorValueid => '48'
        shopColorValuesort => '19'
        shopColorValue_data => NULL
        feature_id => '675'
      }

The entire array did not fit, uploaded to pastebin
Sorting is only necessary for the tsvet1 value, the output colors of shopColorValuevalue must be arranged in alphabetical order.
I tried to write a function, but there is not enough knowledge in this matter:
sort($filters);
        foreach ($filters as $key => $val) {
            echo "$key = $val\n";
        }

Outputs:
0 = Array 1 = Array 2 = Array 3 = Array 4 = Array 5 = Array

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2019-12-05
@glaphire

We need the usort function , and describe the sorting law separately ( discussion examples , it seems easier through Collator)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question