Home > Backend Development > PHP Tutorial > Tips on using the PHParray_multisort function

Tips on using the PHParray_multisort function

墨辰丷
Release: 2023-03-29 20:42:02
Original
1367 people have browsed it

This article mainly introduces the usage skills of PHParray_multisort function. Interested friends can refer to it. I hope it will be helpful to everyone.

The implementation code is as follows:

<?php 
$array[] = array(&#39;id&#39;=>1,&#39;price&#39;=>50);
$array[] = array(&#39;id&#39;=>2,&#39;price&#39;=>70);
$array[] = array(&#39;id&#39;=>3,&#39;price&#39;=>30);
$array[] = array(&#39;id&#39;=>4,&#39;price&#39;=>20);
foreach ($array as $key=>$value){
  $id[$key] = $value[&#39;id&#39;];
  $price[$key] = $value[&#39;price&#39;];
}
array_multisort($price,SORT_NUMERIC,SORT_DESC,$id,SORT_STRING,SORT_ASC,$array);
echo &#39;<pre class="brush:php;toolbar:false">&#39;;
print_r($array);
echo &#39;
'; ?>
Copy after login

Running results:

Array
(
[0] => Array
(
[id] => 2
[price] => 70
)
[1] => Array
(
[id] => 1
[price] => 50
)
[2] => Array
(
[id] => 3
[price] => 30
)
[3] => Array
(
[id] => 4
[price] => 20
)
)
Copy after login

Summary: The above is the entire content of this article, I hope it can help everyone learn Helps.

Related recommendations:

Data transmission CURL instance analysis in PHP

##Example of website directory scanning indexing tool based on PHP

How to implement fuzzy query in PHP

The above is the detailed content of Tips on using the PHParray_multisort function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template