Answer the question
In order to leave comments, you need to log in
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'
}
sort($filters);
foreach ($filters as $key => $val) {
echo "$key = $val\n";
}
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
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 questionAsk a Question
731 491 924 answers to any question