以可读/分层格式显示数组

2022-08-30 07:21:31

下面是为我的数组提取数据的代码

<?php
    $link = mysqli_connect('localhost', 'root', '', 'mutli_page_form');

    $query = "SELECT * FROM wills_children WHERE will=73";

    $result = mysqli_query($link, $query) or die(mysqli_error($link));

    if ($result = mysqli_query($link, $query)) {

    /* fetch associative array */
    if($row = mysqli_fetch_assoc($result)) {
        $data = unserialize($row['children']);
    }

    /* free result set */
    mysqli_free_result($result);
    }
?>

当我使用print_r($data)时,它读作:

Array ( [0] => Array ( [0] => Natural Chlid 1 [1] => Natural Chlid 2 [2] => Natural Chlid 3 ) ) 

我希望它读作:

自然儿童 1
自然儿童 2
自然儿童 3


答案 1

而不是

print_r($data);

尝试

print "<pre>";
print_r($data);
print "</pre>";

答案 2
print("<pre>".print_r($data,true)."</pre>");

推荐