$row['column'] 在 PHP 中 [英] $row['column'] in PHP
问题描述
大家好,我看到了一个带有 $row['columnname']
的代码.代码是
Hello guys I have seen a code with $row['columnname']
.The code is
$myQuery = "SELECT * FROM information_schema.columns WHERE table_name = '$tabname'";
$re = mysql_query($myQuery);
while($row = mysql_fetch_array ($re)){
if(!empty ($row)){
$col_name = $row['COLUMN_NAME'];
$myQuery = "SELECT ".$col_name." FROM ".$tabname." WHERE sampleid='".$sid."'";
echo "<br>".$myQuery;
$reqq = mysql_query($myQuery);
$roww = mysql_fetch_array($reqq);
echo "<br>".$roww[$col_name];
}
}
我的问题是$row[]
在php中有什么用?
My question is what is the use of $row[]
in php?
是用来嵌入列值如 $row['columnname']
还是只是添加一个变量如 $row[$anyvariable]
.
Is it used to embed the column value like $row['columnname']
or just adding a variable like $row[$anyvariable]
.
推荐答案
这就是所谓的括号表示法.$row
是一个数组,它有属性.在这种情况下,它具有命名属性,因此它是一个关联数组.关联数组具有键/值对.它看起来像这样:
That is called bracket notation. $row
is an array, which has properties. In this case, it has named properties, so it is an associative array. An associate array has key/value pairs. It looks like this:
$myArray = [
'key' => 'value'
];
要回显上述属性的值,您可以使用 echo $myArray['key'];
To echo the value of the property above, you would use echo $myArray['key'];
在您包含的特定代码中,属性名称是COLUMN_NAME"并且它有一个值.代码将该值分配给变量 $col_name
.
In the specific code you included, the property name is "COLUMN_NAME" and it has a value. The code assigns that value to the variable $col_name
.
这是另一个示例用法,可帮助澄清所有这些:
Here's another sample usage to help clarify all of this:
$people = [
'Susan' => [
'Age' => 24,
'Phone' => '555-123-4567'
],
'Jack' => [
'Age' => 27,
'Phone' => '555-9876-5432'
]
];
echo $people['Jack']['Age']; // 27
这篇关于$row['column'] 在 PHP 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!