|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
elyod_72 Smarty n00b
Joined: 11 Aug 2008 Posts: 4
|
Posted: Fri Feb 20, 2009 7:27 pm Post subject: Comparing array items in a foreach loop. |
|
|
I have an associative array that I am using foreach to loop thru. In deciding whether or not to display portions of a row, I want to look at the previous row's contents and only display if the contents is different.
Below is an example:
I have the following associative array:
Array(
[0] => Array(
[Player] => Dave
[Type] => Cell
[Number] => 665-123-1234
)
[1] => Array(
[Player] => Dave
[Type] = >Home
[Number => 665-124-2234
)
[2] => Array(
[Player] => Joe
[Type] => Cell
[Number] => 665-321-4325
)
[3] => Array(
[Player] => Joe
[Type] => Home
[Number] => 665-333-1234
)
)
I want Dave's name to display for row [0] because it is the first time it apperars. Then for row [1], I don't want to display his name because it is the same as row [0]. Then for row [2], since row [2]'s name is different than row[1], I want to display Joe's name. Then on row [3], I don't want to dispay Joe's name since it is the same as row [2].
Is there a way to do this in a foreach loop?
Any help on this would be greatly appreciated. |
|
Back to top |
|
elyod_72 Smarty n00b
Joined: 11 Aug 2008 Posts: 4
|
Posted: Fri Feb 20, 2009 8:18 pm Post subject: |
|
|
I figured it out, but it could not be done using foreach. I had to use the section tag instead. Section allows me to use prev_index to compare the previous contents versus the current index contents.
This works great! |
|
Back to top |
|
draxander Smarty n00b
Joined: 12 May 2016 Posts: 3
|
Posted: Thu May 12, 2016 10:17 am Post subject: |
|
|
Could you explain how you solved this?
I've a similar problem and don't know how to solve it.
(I know, this thread is old ) |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu May 12, 2016 10:38 pm Post subject: |
|
|
draxander wrote: | (I know, this thread is old ) | Necrophilia is bad for your afterlife. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|