How to point last element of an array in PHP?

General discussion on PHP
Post Reply
ashi4275
Posts: 15
Joined: Fri Jul 15, 2016 10:02 am

How to point last element of an array in PHP?

Post by ashi4275 » Fri Nov 04, 2016 10:59 am

Hi, While learning PHP programming & applications, I encountered an issue where I need to point last element of an array in PHP. I have searched in many (DELETED) for this solutions but still issue remains the same. Hoping to get a solution from the fellow tech experts.

User avatar
zend_eyalt
Posts: 282
Joined: Thu Jan 22, 2009 3:16 pm

Re: How to point last element of an array in PHP?

Post by zend_eyalt » Sun Nov 06, 2016 2:32 pm


ashi4275
Posts: 15
Joined: Fri Jul 15, 2016 10:02 am

Re: How to point last element of an array in PHP?

Post by ashi4275 » Mon Nov 07, 2016 10:51 am

thnks for supporting :)

ashi4275
Posts: 15
Joined: Fri Jul 15, 2016 10:02 am

Post by ashi4275 » Mon Nov 07, 2016 10:55 am

:)

judy6640
Posts: 8
Joined: Sat Jun 17, 2017 10:07 am

Re: How to point last element of an array in PHP?

Post by judy6640 » Sat Jun 17, 2017 10:21 am

ashi4275 wrote:Hi, While learning PHP programming & applications, I encountered an issue where I need to point last element of an array in PHP. I have searched in many (DELETED) for this solutions but still issue remains the same. Hoping to get a solution from the fellow tech experts.
$ Total = count ($ array);
$ Counter = 0;
Foreach ($ array as $ key => value) {
   $ Counter ++;
   If ($ counter == $ total) {
     // do something with the last element ...
   }
   Else {
     // do something with element
   }
}

Post Reply