|
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 |
jj77 Smarty n00b
Joined: 16 Apr 2014 Posts: 2
|
Posted: Wed Apr 16, 2014 7:23 pm Post subject: Smarty 2 - searching within a array |
|
|
I was wondering if there is a better way of doing this rather than within a foreach loop.
I have an array like this:
Code: |
$products Array()
0=> Array (1)
productid => "2324"
product_title => "product 1"
Array()
1=> Array (1)
productid => "4563"
product_title => "product 2"
Array()
2=> Array (1)
productid => "7664"
product_title => "product 3"
Array()
3=> Array (1)
productid => "4897"
product_title => "product 4"
|
In a template I will know the productid but I won't know what the array numeric key is. For example, if the productid is 4563 I need to search the array to match this productid and then get the numeric key, so that I can access the array like this {$products.1.product_title}
What's the best way of doing this?
Thanks for any advice. |
|
Back to top |
|
jj77 Smarty n00b
Joined: 16 Apr 2014 Posts: 2
|
Posted: Thu Apr 17, 2014 3:03 pm Post subject: |
|
|
I've sorted this out now, I'm doing the array search on the php side rather than the template side, much easier. |
|
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
|