Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty 2 - searching within a array

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
jj77
Smarty n00b


Joined: 16 Apr 2014
Posts: 2

PostPosted: Wed Apr 16, 2014 7:23 pm    Post subject: Smarty 2 - searching within a array Reply with quote

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
View user's profile Send private message
jj77
Smarty n00b


Joined: 16 Apr 2014
Posts: 2

PostPosted: Thu Apr 17, 2014 3:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP