0

在下面的:

<?php
$test = array(
    array("fName" => "Paul", "lName" => "Jones", "Age" => "31"),
    array("fName" => "Mike", "lName" => "Hunt", "Age" => "3"),
    array("fName" => "John", "lName" => "Doe", "Age" => "32")
);
?>

<pre> <?php var_dump($test) ?> </pre>

<?php
foreach($test[0] as $key => $value) {
    echo $value . " " ;
}

?>

这输出Paul Jones 31

我怎样才能让它只输出名字fNames

IEPaul, Mike, John

4

4 回答 4

5
foreach($test as $person) {
    echo $person['fName'] . " " ;
}

// output: Paul Mike John 
于 2012-04-17T22:52:35.757 回答
2

您可能想要遍历主数组而不是其中的单个元素。

foreach($test as $item) {
    echo $item['fName'];
}
于 2012-04-17T22:53:15.647 回答
1
foreach($test as $value) {
  echo $value['fName'] . ", " ;
}
于 2012-04-17T22:51:07.997 回答
1
foreach ($test as $arr)
    echo $arr['fName'] . ', ';
于 2012-04-17T22:52:58.527 回答