How to access multidimensional array element in smarty template?

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago


I'm assigning one multidimensional array named $user_details to smarty from PHP as follows:

$smarty->assign('user_details', $user_details);

The actual array $user_details looks like follows:

Array
(
    [user_id] => 263129476e186da1dc28c8d0b5e48521
    [user_first_name] => Nishant
    [user_last_name] => Dey
    [user_name] => agridipankar@in.com
    [user_password] => 1994nishant
    [user_email] => agridipankar@in.com
    [user_dob] => 
    [user_subscription] => lifetime
    [user_reg_date] => 18/09/2012 04:09:11 pm
    [user_last_login] => 1351274390
    [user_last_logged_in] => 26/10/2012 11:29:50 pm
    [user_mobile_number] => 9436525368
    [assigned_tests_data] => Array
        (
            [0] => Array
                (
                    [test_name] => JEE XI Test : Mathematics Full Syllabus 2
                    [test_no_questions] => 100
                    [test_max_score] => 400.000
                    [test_duration] => 7200
                )

            [1] => Array
                (
                    [test_name] => JEE XI Test : Mathematics Full Syllabus 1
                    [test_no_questions] => 100
                    [test_max_score] => 400.000
                    [test_duration] => 7200
                )

            [2] => Array
                (
                    [test_name] => JEE XI Test : Probability
                    [test_no_questions] => 50
                    [test_max_score] => 200.000
                    [test_duration] => 3600
                )

            [3] => Array
                (
                    [test_name] => JEE XI Testlet : Probability 2
                    [test_no_questions] => 15
                    [test_max_score] => 60.000
                    [test_duration] => 1200
                
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago


This will work for accessing the internal array key element and the subsequest arrays contained it.

 width="100%"  class="base-table" cellspacing="0" cellpadding="0" border="0" id="users_test_listing">
         
          
             width="40%" class="sorter-false" style="text-align:center;">Test Name
             width="20%" class="sorter-false" style="text-align:center;">No. of Questions
             width="20%" class="sorter-false" style="text-align:center;">Total Marks
             width="20%" class="sorter-false" style="text-align:center;">Duration
          
        
         
          {foreach from=$user_details.assigned_tests_data item=test_data}
          
             valign="top">{$test_data.test_name}
             align="center" valign="top">{$test_data.test_no_questions}
             align="center" valign="top">{$test_data.Marks}
             align="center" valign="top">{$test_data.Time} Hrs
             
          {/foreach}
        
      

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.