【发布时间】:2023-03-18 04:09:01
【问题描述】:
我的多维数组有问题。我在这里遇到了两个问题:当我打印我的数组时,我得到了每个对象两次。我的下一个问题是我想得到一个列的结果,例如:[strProductNaam] => 可调哑铃 - Bowflex 552i - 2 到 24 公斤。有人可以帮我吗?
提前致谢!
<?php
require('php/connection.php');
$sql = "SELECT * FROM tblProduct";
$result = sqlsrv_query($conn,$sql);
if( $result === false ) {
die( print_r( sqlsrv_errors(), true));
}
while($row = sqlsrv_fetch_array($result)) {
$datas[] = $row;
}
echo '<pre>';
print_r($datas);
echo '</pre>';
foreach($datas as $data){
echo $data['strProductNaam'] ." ";
}
sqlsrv_free_stmt($result);
sqlsrv_close($conn);
?>
之后的结果:print_r($datas):
Array
(
[0] => Array
(
[0] => 1
[ID] => 1
[1] => 1
[CategorieID] => 1
[2] => Adjustable Dumbbells - Bowflex 552i - 2 to 24 kg
[strProductNaam] => Adjustable Dumbbells - Bowflex 552i - 2 to 24 kg
[3] => 499
[intPrijs] => 499
[4] => Easy to adjust
[strPlusPunt1] => Easy to adjust
[5] => Saving space
[strPlusPunt2] => Saving space
)
[1] => Array
(
[0] => 2
[ID] => 2
[1] => 1
[CategorieID] => 1
[2] => Dumbbell 15kg
[strProductNaam] => Dumbbell 15kg
[3] => 28.95
[intPrijs] => 28.95
[4] => Easy to expand
[strPlusPunt1] => Easy to expand
[5] => Easily adjustable
[strPlusPunt2] => Easily adjustable
)
【问题讨论】:
-
我想得到一列的结果,例如:[strProductNaam]你有一个
foreach,它不起作用吗?
标签: php arrays sql-server multidimensional-array