|
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 |
gordonisnz Smarty Regular
Joined: 05 Sep 2009 Posts: 70
|
Posted: Sat May 08, 2021 7:27 am Post subject: Find array value without foreach? |
|
|
Hi, Ive got a query regarding getting data from an array.
DATA1 >> day >> 5
DATA1 >> month >> 3
DATA1 >> year >> 2020
DATA2 >> day >> 5
DATA2 >> month >> 3
DATA2 >> year >> 2020
DATA3 >> day >> 5
DATA3 >> month >> 3
DATA3 >> year >> 2020
ive got an outer FOREACH - (more data to the left of 'data1' / 'data2' etc..) and im left with the above arrays - but I only have ONE array at a time with just day, month & year)
is there a way to get the day value - without doing a separate foreach to find the day/month year - REGARDLESS of 'DATA1' / 'DATA2' / 'DATA3 etc ?
Or will i need another foreach on this sub-array ? |
|
Back to top |
|
gordonisnz Smarty Regular
Joined: 05 Sep 2009 Posts: 70
|
Posted: Sat May 08, 2021 8:07 am Post subject: |
|
|
Ive found another thread to put "0" - but nothing seems to be working,.
$array.0.DAY
$array[0]["DAY"]
$array[0].DAY |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Tue May 11, 2021 8:13 pm Post subject: |
|
|
My experiment:
Code: |
{$Class|@print_r}
{$Class|array_column:3|@print_r}
|
Code: | Array
(
[0] => Array
(
[0] => A
[1] => B
[2] => C
[3] => D
)
[1] => Array
(
[0] => E
[1] => F
[2] => G
[3] => H
)
[2] => Array
(
[0] => I
[1] => J
[2] => K
[3] => L
)
[3] => Array
(
[0] => M
[1] => N
[2] => O
[3] => P
)
)
1 << Residue from print_r
Array
(
[0] => D
[1] => H
[2] => L
[3] => P
)
1 << Residue from print_r |
You could use:
{$Class|array_column:'day'}
(I note your array has 'day' but you are using DAY - using the wrong lettercase.) |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat May 15, 2021 11:37 am Post subject: |
|
|
Code: | <pre>{$variable|print_r:true}</pre> |
|
|
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
|