Jump to content


Photo

Skip First Two Items in Array


  • Please log in to reply
11 replies to this topic

#1 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 10 October 2006 - 12:44 AM

How can I skip the first two items in an array. I'm trying to display a bunch of images within a directory by grabbing all the file names with php. Before the image files it shows . and .. so i'm wondering how I can remove them.

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 10 October 2006 - 12:50 AM

array_shift()
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 10 October 2006 - 12:58 AM

how would I use that to skip the first two items in an array? I tried to look it up on the net through google but it didn't really bring up any results that explained what I wanted.

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 10 October 2006 - 01:00 AM

array_shift($yourarray);

how about trying the manual instead.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 brendandonhue

brendandonhue
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 10 October 2006 - 01:10 AM

You can use glob() to just get the names of the files you want, and not have . and .. in your array in the first place.

#6 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 10 October 2006 - 01:17 AM

examples?

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 10 October 2006 - 01:28 AM

http://ca.php.net/ma...nction.glob.php

You can check the user notes for examples.
Legend has it that reading the manual never killed anyone.
My site

#8 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 11 October 2006 - 01:45 AM

ok i'm useless.. can someone give me an example of how to do this.. i still can't figure it out by reading those pages.

#9 brendandonhue

brendandonhue
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 12 October 2006 - 07:56 PM

What files are you trying to list? *.gif, *.jpg, etc?

#10 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 12 October 2006 - 10:21 PM

yes. I'm trying to display image files.

#11 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 12 October 2006 - 10:40 PM

Don't put the . and .. in the array to start with.

And if you want an example,

http://www.php.net/readdir
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#12 brendandonhue

brendandonhue
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 13 October 2006 - 11:00 PM

yes. I'm trying to display image files.

$images = glob("/images/{*.jpg,*.gif, *.png}", GLOB_BRACE);




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users