RE: [PHP] assoc array question
Off teeh top of my novice head I think count() or sizeof() is what your looking for. -Original Message- From: Alexander Ross [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 15, 2002 5:23 PM To: [EMAIL PROTECTED] Subject: [PHP] assoc array question I have this: (note that $info is an Assoc Array while (list ($key, $val) = each ($info)) { do stuff } I would like to do slightly different stuff if I'm at the very first, or very last item in the array. How do I do this. Below is the pseudo code which would be ideal: while (list ($key, $val) = each ($info)) { if(onFirstKey or onLastKey) do fun stuff else do other stuff } Please help. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] assoc array question
But what about the first position?? -Original Message- From: Brian V Bonini [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 15, 2002 5:37 PM To: Alexander Ross; [EMAIL PROTECTED] Subject: RE: [PHP] assoc array question Off teeh top of my novice head I think count() or sizeof() is what your looking for. -Original Message- From: Alexander Ross [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 15, 2002 5:23 PM To: [EMAIL PROTECTED] Subject: [PHP] assoc array question I have this: (note that $info is an Assoc Array while (list ($key, $val) = each ($info)) { do stuff } I would like to do slightly different stuff if I'm at the very first, or very last item in the array. How do I do this. Below is the pseudo code which would be ideal: while (list ($key, $val) = each ($info)) { if(onFirstKey or onLastKey) do fun stuff else do other stuff } Please help. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] assoc array question
aha!! array_keys !!! Brian V Bonini [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Off teeh top of my novice head I think count() or sizeof() is what your looking for. -Original Message- From: Alexander Ross [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 15, 2002 5:23 PM To: [EMAIL PROTECTED] Subject: [PHP] assoc array question I have this: (note that $info is an Assoc Array while (list ($key, $val) = each ($info)) { do stuff } I would like to do slightly different stuff if I'm at the very first, or very last item in the array. How do I do this. Below is the pseudo code which would be ideal: while (list ($key, $val) = each ($info)) { if(onFirstKey or onLastKey) do fun stuff else do other stuff } Please help. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] assoc array question
while (list ($key, $val) = each ($info)) { do stuff } $count = 0; $last = sizeof($info); While (list($key, $val) = each($info)) { if ($count == 0) { // first time through } if ($count == $last) { // last time through } // do stuff $count++; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] assoc array question
last($info); $last_key=key($info); reset($info); $first_key=key($info); foreach($info as $key=$val) { switch($key) { case $first_key: ... stuff for first element ... break; case $last_key: ... stuff for last element ... break; default: ... stuff for everything else ... break; } } On Thu, 15 Aug 2002, Alexander Ross wrote: I have this: (note that $info is an Assoc Array while (list ($key, $val) = each ($info)) { do stuff } I would like to do slightly different stuff if I'm at the very first, or very last item in the array. How do I do this. Below is the pseudo code which would be ideal: while (list ($key, $val) = each ($info)) { if(onFirstKey or onLastKey) do fun stuff else do other stuff } Please help. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php