How do I skip the 1st item of a PHP array when displayed

I have an array that is created from a comma separated list in a database field. (not my DB design, please don’t yell at me - LOL)

The array is called “$photolist” and I create the Array like this:

$photolist = explode(",",$row_rs_photos['photos']);

Curently I loop through this array in the following manner (kept simple for this post)

<?php foreach ($photolist as &$photovalue) {
        echo $photovalue . ", " ;
} ?>

I know, the code above is basically useless. It just created a “comma separated list” from an array after creating the array from the comma separated list :slight_smile: I actually run a much more complex procedure in there, but that is not important at this time.


1: Check to see if the array has more than 1 entry.
2: If there is more than one entry, I need the first entry removed when displayed,

EG: If there are 19 entries, I need the first one removed so it doesn’t show. If there is only 1 entry, don’t remove that first and only entry.

What is the best approach to do this?

I hope this is clear enough to understand what I am trying to do.
Thanks in advance for your time.

I would use [fphp]array_slice[/fphp] with a ternary operator in it

$photolist = explode(",",$row_rs_photos['photos']);
$photolist = array_slice($photolist, count($photolist)==0? 0 : 1);

ScallioXTX: Thanks, that does the trick for me.
I did have to change “0?” to “1?” but it is working perfectly. Thanks.


And as of PHP 5.3.0 there is also str_getcsv() (:

I posted in haste last night, but don’t both of the functions above use the first line as the keys for the array? (and hence answer the OPs question).

No, (str_|f)getcsv doesn’t care about any first line or headers. As in the original question, its up to the developer to work out if/where headers are and how to work with/around them.