Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Ordenar matrices múltiples por cadena php

Tengo esas matrices, ¿cómo ordenar por cadena? Solo necesito ordenar varias matrices. Intento ordenar (), pero no tuve suerte, me dio un error.

 array(1) { [0]=> string(2) "10" } array(1) { [0]=> string(1) "2" } array(1) { [0]=> string(1) "3" } array(1) { [0]=> string(1) "4" }

Este es mi código ahora

 <?php $myfiles = glob('articol/*'); foreach($myfiles as $filename){ if(is_file($filename)){ $file = file_get_contents($filename); $html = $file; preg_match('/<p class="id" hidden>(.*?)<\/p>/s', $html, $id) // Return 1 or 2 or 3 .... or 10 ; $idFinal = array($id[1]); sort($idFinal); echo "<pre>"; var_dump($idFinal); echo "</pre>"; } } ?>
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

La función sort() es correcta.

 $a1 = ["10"]; $a2 = ["2"]; $a3 = ["3"]; $a4 = ["4"]; $array = array_merge($a1, $a2, $a3, $a4); $new = array_map(function($e) { return (int) $e; },$array); sort($new); print_r($new);

producción

 Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 10 )

ACTUALIZAR

 // Array ( [0] => 10 ) Array ( [0] => 2 ) Array ( [0] => 3 ) Array ( [0] => 4 ) Array ( [0] => 5 ) Array ( [0] => 6 ) Array ( [0] => 7 ) Array ( [0] => 8 ) Array ( [0] => 9 ) Array ( [0] => 1 ) $mainArray = [ ["10"], ["2"],["3"], ["4"], ]; function mergeAndSortArrays($arr) { $newArr = array_map(function($e) { return (int) $e[0]; }, $arr); sort($newArr); return $newArr; }

producción

 Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 10 )
over 4 years ago · Santiago Trujillo Report

0

Aquí hay formas de ordenar arreglos en php

 sort() - sort arrays in ascending order rsort() - sort arrays in descending order asort() - sort associative arrays in ascending order, according to the value ksort() - sort associative arrays in ascending order, according to the key arsort() - sort associative arrays in descending order, according to the value krsort() - sort associative arrays in descending order, according to the key

Elegir uno.

 $nums = array("10", "2", "5"); sort($nums); print_r($nums); //Array ( [0] => 2 [1] => 5 [2] => 10 )
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!