SPIP

[ar] [ast] [bg] [br] [ca] [co] [cpf] [cs] [da] [de] [en] [eo] [es] [eu] [fa] [fon] [fr] [gl] [id] [it] [ja] [lb] [nl] [oc] [pl] [pt] [ro] [ru] [sk] [sv] [tr] [vi] [zh] Espace de traduction

Download

|table_valeur

June 2010

All the versions of this article:

|table_valeur returns the value associated to a given key in a PHP array or table.


|table_valeur{key,default value}

The |table_valeur filter (since SPIP 1.9) applied to a tag that returns a table, accepts a first parameter as a key in the array and returns the value associated with that key. See details about the #ARRAY tag for a more general explanation about array handling in SPIP.

Example:

returns green.

The optional default value parameter is used to specify a value to be returned if a value is not found (the key does not exist or the tag filtered does not generate an array).

[(#GET{un_tableau}|table_valeur{3,black})] returns black since there is no key 3.

|table_valeur also works with "linearised" arrays, e.g. the arrays returned by the #ENV and #CONFIG tags (even though these tags have their own syntax to access values in the array).

The above array in linearised form [1] looks like this:

a:3:{i:0;s:5:"red";i:1;s:4:"blue";i:2;s:4:"green";}

[(#GET{an_array}|table_valeur{2})] always returns green.

Footnotes


Show the template of this page Site powered by SPIP | Translation area | Private area