Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Foreach in reverse order

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 107
    Comment on it

    We can use array_reverse function to invert the values of array.This way we can allow them to get reverse order. Ex : -

    $data = Array(
      'ProductA',
      'ProductB',
      'ProductC',
      'ProductD',
      'ProductE'
    );
    
    foreach ( array_reverse($data) as $value ) {
      echo sprintf("<li>%s</li>", $value);
    }
    

    Output is like -

    ProductE
    ProductD
    ProductC
    ProductB
    ProductA
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: