How to point last element of an array in PHP?

General discussion on PHP

How to point last element of an array in PHP?

Postby ashi4275 on 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.
ashi4275
 
Posts: 15
Joined: Fri Jul 15, 2016 10:02 am

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

Postby zend_eyalt on Sun Nov 06, 2016 2:32 pm

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

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

Postby ashi4275 on Mon Nov 07, 2016 10:51 am

thnks for supporting :)
ashi4275
 
Posts: 15
Joined: Fri Jul 15, 2016 10:02 am

Postby ashi4275 on Mon Nov 07, 2016 10:55 am

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

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

Postby judy6640 on 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
   }
}
judy6640
 
Posts: 9
Joined: Sat Jun 17, 2017 10:07 am


Return to PHP

Who is online

Users browsing this forum: No registered users and 2 guests