如何使用php中的foreach循环在数组值中检索数组?

时间:2017-02-22 14:30:42

标签: php

我正在研究数组。我很想在数组值中检索数组。任何人都可以解决我的问题。这是我的数组值。我创建了一些代码来检索除了作者键值之外的所有值的值。

arraydata

Array
(
    [0] => Array
        (
            [pub] => Springer Nature
            [title] => Array
                (
                    [0] => Evaluation of Term-based Queries using Possibilistic Ontologies
                )

            [doi] => 10.1007/11370697_8
            [url] => http://dx.doi.org/10.1007/11370697_8
            [author] => Array
                (
                    [0] => stdClass Object
                        (
                            [given] => Yannick
                            [family] => Loiseau
                            [affiliation] => Array
                                (
                                )

                        )

                    [1] => stdClass Object
                        (
                            [given] => Mohand
                            [family] => Boughanem
                            [affiliation] => Array
                                (
                                )

                        )

                    [2] => stdClass Object
                        (
                            [given] => Henri
                            [family] => Prade
                            [affiliation] => Array
                                (
                                )

                        )

                )

        )
)

samplecode.php

<table>
<tr>    
    <th>Title</th>
    <th>DOI</th>
    <th>Publisher</th>
    <th>URL</th>
    <th>Authors</th>
</tr>
    <?php   
    if($results != ''){
        foreach($results as $res){
?>
    <tr>
        <td><?php echo $res['title'][0]; ?></td>
        <td><?php echo $res['doi']; ?></td>
        <td><?php echo $res['pub']; ?></td>
        <td><?php echo $res['url']; ?></td>
        <?php 
                $author = $res['author'][0]['given'];
         ?>
        <td><?php //echo $author; ?></td>
    </tr>
<?php
        }
    }
 ?>
 </table>

0 个答案:

没有答案