Published on 11/24/2020
Published by Praveen Gupta
Sample for Array Creation with different way
An array we are storing multiple values in one single variable
arr.create
- Build an array
- It returns: array
Syntax:
1 2 3 4 |
[arr.create set="template.arr_variable"] [key1]value1[/key1] [key2]value2[/key2] [/arr.create] |
E.g – “variable” you need to place variable name from which you can access an array
1 2 3 4 5 |
[arr.create set="template.args"] [post_type]psuedo_poetries[/post_type] [order]DESC[/order] [orderby]ID[/orderby] [/arr.create] |
_________________________________________________
aw2.set_array | module.set_array | template.set_array | env.set_array
Set an array
Scope Name: env(Global), module, template
Syntax:
1 2 3 4 5 6 7 |
[aw2.set_array variable_name key1="value1" key2="value1" /] [template.set_array variable_name key1="value1" key2="value1" /] [module.set_array variable_name key1="value1" key2='value1' /] [env.set_array variable_name key1="value" key2='value3" key3="value3" /] |
Example:
1 2 3 4 5 6 7 |
[aw2.set_array module.args meta_key="key_name" meta_value="{template.meta_value}" ] [module.set_array args.new meta_key="key_name" meta_value="{template.meta_value}" ] [template.set_array meta.new meta_key="key_name" meta_value="{template.meta_value}" ] [env.set_array post_id="{template.post.ID}" content="{template.post.post_content}" module.args /] |
_________________________________________________
arr.set
Set a value in an array
syntax –
1 2 3 4 |
[arr.set setting_variable key1=”value” key2=”value3″ key3=”value3″ /] |
Example:
1 |
[arr.set module.args post_id=”{template.post.ID}” content=”{template.post.post_content}” /] |
_________________________________________________
Array Merge
Suppose you are getting multi Array from anywhere but there is a blank an array any of them
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
[template.set_array arr1 key1="a" key2="b" /] [template.set_array arr2 key3="c" key4="d" /] [template.set_array arr3 key5="e" key6="f" /] [template.set_array arr4 key7="g" key8="h" /] [php.is_array p1="{template.arr1}" set="template.is_array1" /] [php.is_array p1="{template.arr2}" set="template.is_array2" /] [php.is_array p1="{template.arr3}" set="template.is_array3" /] [php.is_array p1="{template.arr4}" set="template.is_array4" /] [arr.create set="template.x" /] [if.true template.is_array1] [php.array_merge p1="{template.x}" p2="{template.arr1}" set="template.x" /] [/if.true] [if.true template.is_array2] [php.array_merge p1="{template.x}" p2="{template.arr2}" set="template.x" /] [/if.true] [if.true template.is_array3] [php.array_merge p1="{template.x}" p2="{template.arr3}" set="template.x" /] [/if.true] [if.true template.is_array4] [php.array_merge p1="{template.x}" p2="{template.arr4}" set="template.x" /] [/if.true] |
Note: We will make a php code later