SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: order by number

  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    order by number

    I have 4 variables like the below.
    Code:
    code
    
    $a=48;
    $b=9;
    $c=52;
    $d=183;
    I like to produce "9 48 52 183" with the code above.

    The would-be code below doesn't work correctly, but I hope it shows what I want.

    Code:
    would-be code
    
    echo order($a, $b, $c, $d);
    
    target result
    9
    48
    52
    183
    How can I get my target result above with the 4 variables?

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I guess one way is to put them in an array:
    PHP Code:
    $a=48;
    $b=9;
    $c=52;
    $d=183;

    $e = array($a$b$c$d);

    sort$e );

    foreach(
    $e as $f){
    echo 
    $f PHP_EOL;

    Kinda begs the question why can you not assign them to an array as you get these figures?

    $a[] = where ever you got this number from


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •