Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

How to access multidimensional array element in smarty template?

Course Queries Syllabus Queries

Max. 2000 characters
Replies

usr_profile.png

User

( 4 months 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
                
usr_profile.png

User

( 4 months ago )


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

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

what's your interest