这是我想要实现的一个非常简化的示例:
GIFT
sender | type
phil | 1
phil | 2
在这里,1 = 蛋糕,2 = 松饼。
$table = query("SELECT sender, type FROM users WHERE sender = Phil");
foreach ($table as $row) {
$sender = $row['sender'];
$type = $row['type'];
echo '$sender has bought a $type';
}
这将输出:
Phil has bought a 1
Phil has bought a 2
我怎样才能得到下面的输出呢?
Phil has bought a cake
Phil has bought a muffin
我应该使用数组吗?
$type = array(
1 => 'cake',
2 => 'muffin'
);
问题是 $type 已经定义为 $row['type']。