Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8843963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:22:03+00:00 2026-06-14T11:22:03+00:00

I have an array ( @tasks ) from a database select and I want

  • 0

I have an array (@tasks) from a database select and I want to display the first on its own and then loop through any others.

There will always be one item in the array but there may or may not be more than one.

What’s the best way to show the first one and then loop through any remaining items, if there are any more?

I thought I found something similar on SO the other day but I can’t seem to find it again.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:22:04+00:00Added an answer on June 14, 2026 at 11:22 am
    1.9.3-p327 > a = [1,2,3]
     => [1, 2, 3] 
    1.9.3-p327 > first, *the_rest = *a
     => [1, 2, 3] 
    1.9.3-p327 > first
     => 1 
    1.9.3-p327 > the_rest
     => [2, 3] 
    

    However, in the above case, if a = [1] then the_rest will end up being nil (at least in ruby 1.9, dunno about 1.8)

    You could also use .shift to remove the first element like so:

    1.9.3-p327 > first = a.shift
     => 1 
    1.9.3-p327 > first
     => 1 
    1.9.3-p327 > a
     => [2, 3] 
    1.9.3-p327 > 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have a main activity that takes elements from a database and displays them
I have a perl array of to-do tasks that looks like this: @todos =
I have a database that looks like this: I can generate a tree from
I have a database with 16000 rows. I want to grab a random 400
I have the Array collection of objects like this Class User { private $tasks;
I have just started creating my first website, which is backed by a database
I have a byte[] array from a bitmap. I could save it to a
I have a task where i need to write a multidimensional array to HDFS.
I have array INPUTFILES with n files INPUTFILES=( file_0 ... files_n-1 ) And i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.