Hello,
I have an array $city . it has duplicates inside. I need to create an UDT or some Smarty magic to do array_unique($city); to remove dupicates, and then count the new unique array. Can anybody help with it?
help to create udt with array_unique function
-
- New Member
- Posts: 8
- Joined: Sat Oct 25, 2014 11:47 pm
Re: help to create udt with array_unique function
I use similar here https://www.cmscanbesimple.org/blog/add ... ews-module
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Re: help to create udt with array_unique function
try {$city|@array_unique|@count}
Re: help to create udt with array_unique function
Lot of possibilities in Smarty.
Code: Select all
{* define an array for testing *}
{$array=["b","a","b","c","c"]}
{* print array *}
{$array|print_r}
{* assign modified array to new variable "unique" and print $unique *}
{assign var="unique" value=$array|array_unique}
{$unique|print_r}
{* short way for example above *}
{$unique=$array|array_unique}
{$unique|print_r}
{* you can use php functions too in smarty! *}
{$unique=array_unique($array)}
{$unique|print_r}
{* make unique, count and print*}
{$array|array_unique|count}
{* make unique, count and print - the 'php edition' *}
{count(array_unique($array))}
{* make unique, count and store in "cnt" variable for later/multiple use *}
{$cnt=count(array_unique($array))}
{$cnt}
-
- New Member
- Posts: 8
- Joined: Sat Oct 25, 2014 11:47 pm
Re: help to create udt with array_unique function
thanks for your reply, works perfectly!
I have another question about combining an array.
I`m getting variables from a {foreach} loop from a list of child pages (using cgsimple get_children).
and they come as a list of arrays. Each loop gives a new array with 1 var.
How can I get this all together in one array? or my array_unique function wount work.
I have another question about combining an array.
I`m getting variables from a {foreach} loop from a list of child pages (using cgsimple get_children).
and they come as a list of arrays. Each loop gives a new array with 1 var.
How can I get this all together in one array? or my array_unique function wount work.
Re: help to create udt with array_unique function
In your foreach loop, assign the value to a var, eg 'onevar'. Then after each
foreach loop:
You can then do your array_unique thing on $allvars.
foreach loop:
Code: Select all
{append var='allvars' value=$onevar}