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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I make a set of different strings using a loop? is it possible?

    The following is just an example, but is exactly what I need to know to apply it to the real code. How can I do it?

    PHP Code:
    /*THIS NUMBER WILL BE DEFFERENT EACH TIME */

    $number 5;

    for (
    $i 1$i <= $number$i++) {

    /* THIS DOESNT WORK */

      
    $string_$i = ($i 5);


    So the result should be:
    PHP Code:
    $string_1 6;
    $string_2 7;
    $string_3 8;
    $string_4 9;
    $string_5 10

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    arrays may be easier in the long run ... but anyway , look for 'variable variables' section of the manual...

    PHP Code:
    <?php
    $number 
    5;

    for ( 
    $i $i <= $number ; ++$i ) {
        ${
    'string_'.$i} = $i $number ;
    }

    echo 
    $string_5;
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks firepages, after a long fight it finally worked!


  •  

    Posting Permissions

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