Get Smarty

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

Name

append() — Ajoute un élément à un tableau assigné

Description

void append(mixed var);
void append(string varname,
            mixed var,
            bool merge);

Si vous utilisez cette fonction avec une chaîne de caractères, elle est convertie en tableau auquel on ajoute ensuite l'élément. Vous pouvez explicitement passer des paires nom/valeur. Si vous passez le troisième paramètre (optionel) à TRUE, la valeur sera fusionnée avec le tableau plutôt que d'être ajoutée.

Note technique

Le paramètre merge respecte les clés du tableau, donc, si vous fusionnez deux tableaux indexés numériquement, ils peuvent se recouvrir les uns les autres ou aboutir à des clés non séquentielles. Ceci est diférent de la fonction PHP array_merge() qui élimine des clés numériques et les renumérote.

Example 13.1. Exemple avec append


<?php
// passe des paires nom/valeur
$smarty->append("Nom","Fred");
$smarty->append("Adresse",$address);

$array = array(1 => 'un', 2 => 'deux');
$smarty->append('X', $array);
$array2 = array(3 => 'trois', 4 => 'quatre');
// La ligne suivante ajoute un second élément au tableau X
$smarty->append('X', $array2);

// passe un tableau associatif
$smarty->append(array('Ville' => 'Lincoln','Pays' => 'Nebraska'));
?>

   

Voir aussi append_by_ref(), assign() et get_template_vars().

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 2 plus 3? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk