Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1

    Ordinare valori numerici

    Se io ho 9 variabili numeriche. Come le stampo in ordine decrescente in modo del tutto automatico?

    thx
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2007
    Messaggi
    595
    Codice PHP:
    $array = array();
    $array[] = $var1;
    $array[] = $var2;
    $array[] = $var3;
    $array[] = $var4;
    $array[] = $var5;
    $array[] = $var6;
    $array[] = $var7;
    $array[] = $var8;
    $array[] = $var9;
    sort($array);
    foreach(
    $array as $value)
      echo 
    "$value
    "


  3. #3
    potresti copiare il contenuto delle variabili in un array ed usare una funzione tipo arsort()

  4. #4
    me li stampain ordine ASC
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  5. #5
    grazie ad intra,bi per l'aiuto. Un ultima domanda. se volessi salvare un'altra variabile nello stesso array? me ne serve uno bidimensionale?

    thx
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  6. #6
    Utente di HTML.it
    Registrato dal
    Jan 2007
    Messaggi
    595
    L'istruzione

    $array[] = $var;

    Aggiunge un elemento alla fine dell'array. Dopo di che lo puoi sempre riordinare con

    sort($array);

    Se vuoi che i campi siano NUMERICI puoi fare un cast di tutti gli elementi quando valorizzi l'array, in questo modo

    $array[] = (int)$var;

  7. #7
    Originariamente inviato da Manuelandro
    grazie ad intra,bi per l'aiuto. Un ultima domanda. se volessi salvare un'altra variabile nello stesso array? me ne serve uno bidimensionale?

    thx
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  8. #8
    mi spiego meglio. La soluzione dell'array è ottima. Ora però dovrei assegnare ad ogni variabile anche un nome quindei avere


    80 Antonio
    70 Francesco


    etc etc..

    come faccio?
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  9. #9
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    mmhhhh...
    $nomi=array();
    $nomi[70]="Antonio";

    se vuoi visualizzare tutti valori dell' array

    foreach ($nomi as $key=>$val)
    {
    echo $key." - ".$val;
    }

    ti visualizzarà

    70 - Antonio.


    Spero ti possa essere stato utile... la cosa però non potrà funzionare se anche Pippo ha 70...
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  10. #10
    no a me serve qualcosa di abbinato alla risposta che mik hanno dato in precedenza!
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.