Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: forloop trouble

  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts

    forloop trouble

    I was wondering if anyone out there would have a better cleaner code for the following

    PHP Code:
            if($str2ascii == 0)
                {
                    
    $str2ascii ")";
                }
            if(
    $str2ascii == 1)
                {
                    
    $str2ascii "!";
                }
            if(
    $str2ascii == 2)
                {
                    
    $str2ascii "@";
                }
            if(
    $str2ascii == 3)
                {
                    
    $str2ascii "#";
                }
            if(
    $str2ascii == 4)
                {
                    
    $str2ascii "$";
                }
            if(
    $str2ascii == 5)
                {
                    
    $str2ascii "%";
                }
            if(
    $str2ascii == 6)
                {
                    
    $str2ascii "^";
                }
            if(
    $str2ascii == 7)
                {
                    
    $str2ascii "&";
                }
            if(
    $str2ascii == 8)
                {
                    
    $str2ascii "*";
                }
            if(
    $str2ascii == 9)
                {
                    
    $str2ascii "(";
                } 
    I was trying to do a for loop but I couldnt figure out how to get the !@#... in it maybe there is a built in function or something?

    Thanks

    Crash1hd

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,096
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Have a look at switch. It's a really nice way of formatting this type of code.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahh yes but is there no way to do a forloop that I just cant figure out or is the switch the only answer?

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You could use an array.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #5
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,096
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Even if you used an array, look at what you're doing with each occurrence. It's something different for each one. Array processing would more or less expect you to do the same thing with each occurrence in your array. I think switch is your best bet.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #6
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    PHP Code:
    <?php
    $chars 
    = array(')''!''@''#''$''%''^''&''*''(');
    print 
    $chars[$str2ascii];
    ?>
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    excellent thankyou


  •  

    Posting Permissions

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