SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow A short version of this codes?

    good evening.

    shorter version of this codes?

    Code:
    switch ($link) {
    case 1:
    	$tmpbakcolor[1]="#C0C0C0";
        break;
    case 2:
    	$tmpbakcolor[2]="#C0C0C0";
        break;
    case 3:
    	$tmpbakcolor[3]="#C0C0C0";
        break;
    case 4:
    	$tmpbakcolor[4]="#C0C0C0";
        break;
    case 5:
    	$tmpbakcolor[5]="#C0C0C0";
        break;
    case 6:
    	$tmpbakcolor[6]="#C0C0C0";
        break;
    case 7:
    	$tmpbakcolor[7]="#C0C0C0";
        break;
    case 8:
    	$tmpbakcolor[8]="#C0C0C0";
        break;
    case 9:
    	$tmpbakcolor[9]="#C0C0C0";
        break;
    case 10:
    	$tmpbakcolor[10]="#C0C0C0";
        break;
    
    
        more repeated codes here...
    
    
    case 100:
    	$tmpbakcolor[100]="#C0C0C0";
        break;
    default:
        echo "";
    }

    loop?

    thank you.

  2. #2
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    while($i<=100) {
    if($i == $link) {
    $tmpbakcolor[$link]="#C0C0C0";
    }
    $i++;

    solved!

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Unless the original was in a loop, that's not shorter in terms of processing. This is produce the same results as the original code.
    PHP Code:
    if(1>=$link and $link<=100) {
       
    $tmpbakcolor[$link]="#C0C0C0";
    } else {
       echo 
    "";

    - Robert


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
  •