0

I have a php array I would like get a specific data from it.

 [vxs_data] => Array
    (
        [0] => Array
            (
                [data] => Array
                    (
                        [0] => fsafas
                        [1] => 603
                        [2] => 39
                        [3] => 81
                        [4] => 12
                        [5] => 43
                        [6] => 186
                        [7] => 97
                        [8] => 129
                    )

            )

        [1] => Array
            (
                [data] => Array
                    (
                        [9] => fsdfsa
                        [10] => 60
                        [11] => 30
                        [12] => 184
                        [13] => 12
                        [14] => 7
                        [15] => 176
                        [16] => 132
                        [17] => 119
                    )

            )

        [2] => Array
            (
                [data] => Array
                    (
                        [18] => fsafsa
                        [19] => 60
                        [20] => 3121
                        [21] => 18
                        [22] => 11
                        [23] => 0
                        [24] => 199
                        [25] => 140
                        [26] => 117
                    )

            )

        [3] => Array
            (
                [data] => Array
                    (
                        [27] => dada
                        [28] => 60
                        [29] => 27
                        [30] => 11
                        [31] => 22
                        [32] => 1
                        [33] => 22
                        [34] => 157
                        [35] => 98
                    )

            )

        [4] => Array
            (
                [data] => Array
                    (
                        [36] => ASKLMSDAS
                        [37] => 60
                        [38] => 232
                        [39] => 11
                        [40] => 23
                        [41] => 4
                        [42] => 32
                        [43] => 141
                        [44] => 98
                    )

            )

The content of array about that. I would like to get that data in to table (td) so it would be like this:

<tr>
    <td><a href="#">ASKLMSDAS</a></td><td>33</td>...
</tr>
<tr>
    <td><a href="#">dada</a></td><td>33</td>...
</tr>

So I would like a make link of those first data columns like "ASKLMSDAS" "dada". So I need to do some sort of if clause maybe and foreach?

Thanks so much and sorry about my english.

1
  • if ordering of records in data arrays won't change in table td's, you may use smth like '<tr><td>' . implode('</td><td>, $data_array) . '</td></tr>'`, so you'll get row string) Commented Mar 18, 2011 at 6:25

3 Answers 3

1

Not exactly sure what you're going for, but heres a pretty generally way of making a table from the contents of 2d array. Hopefully you can tweak it to do what you want.

echo "<table>";
foreach($smliiga_data as $row_k => $row_v)
{
     echo "<tr><td><strong>$row_k</strong></td>";
     foreach($row_v['data'] as $k=>$v)
     {
         $str = is_int($v) ? "$k: $v" : "<a href='#'>$k: $v</a>"; //this makes link for the ones that are not numbers
         echo "<td>$str</td>";
     }
     echo "</tr>";
}
echo "</table>";
Sign up to request clarification or add additional context in comments.

Comments

0

This should work:

foreach ($mliiga_data as $row){
    $linktext =  $row[data][0];
    //
    // Dispaly linktext
    //
}

Comments

0
$array = array_reverse($array);

foreach($array as $childArray)
{
   echo '<tr><td><a href="#">';
   echo current($childArray['data']);  // write other html as you want, this will give you the element what you want
   echo '</a></td><td>33</td>...</tr>';
}

2 Comments

Well, I didn't downvote, but I don't think he's asking how to reverse the array, he's asking how to iterate through it and output the table. I think it probably wound up like that in his example because when he went to type up the wanted output, he just looked up at the last two array elements he could see.
instead of cloning an array so you can array_shift and not alter the original you can just directly access first element with current() (this is initially the first)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.