• Sorular
  • Etiketler

Bir php dizi sıralama

2 Cevap php

nasıl ben nums bu diziyi sıralamak yok ...

Array(
  [nums] => Array
   (
    [0] => 34
    [1] => 12
    [2] => 13
   )
  [players] => Array
   (
    [0] => Mike
    [1] => Bob
    [2] => Mary
   )
)

... Ben bu bir olsun ki?

Array(
  [nums] => Array
   (
    [0] => 12
    [1] => 13
    [2] => 34
   )
  [players] => Array
   (
    [0] => Bob
    [1] => Mary
    [2] => Mike
   )
)

2 Cevap

array_multisort($x['nums'],$x['players']);

0

sort function. deneyin

bool sort ( array &$array [, int $sort_flags = SORT_REGULAR ] )

Bu fonksiyon bir diziyi sıralar. Bu işlev tamamlandığında Elements en yükseğe için düzenlenmiş olacak.

Ayrıca kontrol asort and arsort

EDIT

Ben hesabınıza boyutlu dizi sürmedi.

   <?php
    //code derived from comments on the php.net/sort page.
    // $sort used as variable function--can be natcasesort, for example
      function sort2d( &$arrIn, $index = null, $sort = 'sort') {
        // pseudo-secure--never allow user input into $sort
        if (strpos($sort, 'sort') === false) {$sort = 'sort';}
        $arrTemp = Array();
        $arrOut = Array();

        foreach ( $arrIn as $key=>$value ) {
          reset($value);
          $arrTemp[$key] = is_null($index) ? current($value) : $value[$index];
        }

        $sort($arrTemp);

        foreach ( $arrTemp as $key=>$value ) {
          $arrOut[$key] = $arrIn[$key];
        }

        $arrIn = $arrOut;
      }
    ?>
0

etiketler

  • php
  • Sorular
  • Etiketler
Copyright © 2014

Powered by EvrenWeb Int. Media.