X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Pulling value from multi-dimensional array (https://forum.x-cart.com/showthread.php?t=45469)

AMMoyer 02-10-2009 06:28 AM

Pulling value from multi-dimensional array
 
Is there a way to pull a single value directly from a multidimensional array? I have looked through the Smarty documentation and some PHP books I have but no luck.

I use the array to populate a dropdown menu and I want to show the selected name, not the underlying value, in a template. I could do this in the PHP file and assign a $makename variable to use or I think it would be more correct to retrieve the name in the template. Also, the array is dynamic based on what year you have selected.

Example array:
Array (37)
0 => Array (2)
makeid => "58"
makename => "Acura"
1 => Array (2)
makeid => "73"
makename => "Audi"
2 => Array (2)
makeid => "31"
makename => "BMW"
3 => Array (2)
makeid => "45"
makename => "Buick"



exsecror 02-10-2009 08:51 AM

Re: Pulling value from multi-dimensional array
 
In Smarty:

{$array.index.makeid} e.g. {$array.0.makeid} would pull the makeid out of $array[0]

AMMoyer 02-10-2009 09:18 AM

Re: Pulling value from multi-dimensional array
 
Thanks for the input. I guess my question wasn't specific enough.

This array is called $makes and when a selection is made in the drop down menu that it populates, then $make is set to the makeid in the array. IE BMW is selected so now $make = 31.

Now that we have the $makes array and a value for $make, can I get BMW back out to use in a template, because it's more useful than having 31 as a vehicle make.

Thanks.


All times are GMT -8. The time now is 09:29 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.