-1

This isn't critical by any means, but I've got a loop through my users on my website, and i spit out data for each one, something like this

for( $i=1; $i<=999; $i++ ){
    $varA = function_a( $i );
    $varB = function_b( $i );
    $myownvar = 0;
    foreach ($varB AS $b) {
        $myownvar = ++$myownvar;
    }
    print($varA.$varB.$myownvar);
}

I end up with a result like

  • 1 - user_one: (10)
  • 2 - user_two: (4)
  • 3 - user_three: (9)

I was wondering if there was a 'relatively simple' way to turn the data around in a way similar to what I've got it, but print the data based on the $this like this.

  • 1 - user_one: (10)
  • 3 - user_three: (9)
  • 2 - user_two: (4)
4

1 回答 1

1

I'm not real sure what you are trying to accomplish, but if the pattern remains consistent, then you could do something like the following:

for ($i = 1; $i < 10; $i+=2) {
    echo $i;
    echo $i-1;
}

Which outputs:

1032547698

If you don't want the 0, then you could simply check for it, and discard it.

Since you didn't post all of your code, it's hard for me to give much more than that as an example, but I assume you should be able to see how this would apply to your situation.

于 2013-02-15T19:26:10.620 回答