PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, June 28, 2022

[FIXED] how to print an array in smarty?

 June 28, 2022     arrays, foreach, php, smarty     No comments   

Issue

I have an array:

 $team_details = Array ( [id] => 1 [name] => doge_finder [total_rewards] => 52.00524500 [desciption] => team is only of doge miners [created_by] => 20 );

/* assigning to a smarty template */
$smarty->assign("team_record", $team_details);          
$smarty->display($tpl);

In template file:

{foreach from= $team_record key=team item=trecord}
{$trecord[$key].name}
{/foreach}

In result output must be "doge_finder", but I got first initial character of each record in array ie. "1 d 5 t 2"

how can I resolve this problem?


Solution

You don't have to use {foreach} if you just want to print one associative array. Just use $array.key format.

In this case, you should print the name by using:

{$team_record.name}

If you have multiple associative arrays. You can use:

{foreach from=$team_record key=team item=record}
    {$record.name}
{/foreach}


Answered By - fian
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing