PHP追加一个变量';将s值转换为变量名
我是一个PHP初学者。 我想创建多个变量,这些变量的名称应该附加一个值,该值取决于for循环的计数器变量PHP追加一个变量';将s值转换为变量名,php,Php,我是一个PHP初学者。 我想创建多个变量,这些变量的名称应该附加一个值,该值取决于for循环的计数器变量 foreach ( $xmlTagNames as $xmlKey => $xmlTagName ) { if ($xmlTagName == "property") { for($i = 0; $i < 4; $i ++) { $$xmlTagName = $xmlFile->createEl
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$$xmlTagName = $xmlFile->createElement ( $xmlTagName );
}
}
}
foreach($xmlTagNames作为$xmlKey=>$xmlTagName)
{
如果($xmlTagName==“属性”)
{
对于($i=0;$i<4;$i++)
{
$$xmlTagName=$xmlFile->createElement($xmlTagName);
}
}
}
在第七行,我希望变量名如下
$property0、$property1等。如何做到这一点?我同意这些评论:您应该在这里使用数组 但要回答您的问题,请使用以下语法:
${$xmlTagName . $i} = $xmlFile->createElement ( $xmlTagName );
我同意这些评论:你应该在这里使用数组 但要回答您的问题,请使用以下语法:
${$xmlTagName . $i} = $xmlFile->createElement ( $xmlTagName );
我同意这些评论:你应该在这里使用数组 但要回答您的问题,请使用以下语法:
${$xmlTagName . $i} = $xmlFile->createElement ( $xmlTagName );
我同意这些评论:你应该在这里使用数组 但要回答您的问题,请使用以下语法:
${$xmlTagName . $i} = $xmlFile->createElement ( $xmlTagName );
正如@David所说,数组可能是您应该使用的:
$properties = array();
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$properies[] = $xmlFile->createElement ( $xmlTagName );
}
}
}
正如@David所说,数组可能是您应该使用的:
$properties = array();
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$properies[] = $xmlFile->createElement ( $xmlTagName );
}
}
}
正如@David所说,数组可能是您应该使用的:
$properties = array();
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$properies[] = $xmlFile->createElement ( $xmlTagName );
}
}
}
正如@David所说,数组可能是您应该使用的:
$properties = array();
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$properies[] = $xmlFile->createElement ( $xmlTagName );
}
}
}
我同意其他的意见,在这里使用数组会更好
$properties = array();
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$properties['property' . $i] = $xmlFile->createElement ( $xmlTagName );
}
}
}
var_dump($properties);
$properties=array();
foreach($xmlTagName作为$xmlKey=>$xmlTagName)
{
如果($xmlTagName==“属性”)
{
对于($i=0;$i<4;$i++)
{
$properties['property'.$i]=$xmlFile->createElement($xmlTagName);
}
}
}
var_dump($properties);
如果设置为使用变量
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$variableName = $xmlTagName . $i;
$$variableName = $xmlFile->createElement ( $xmlTagName );
}
}
}
foreach($xmlTagNames作为$xmlKey=>$xmlTagName)
{
如果($xmlTagName==“属性”)
{
对于($i=0;$i<4;$i++)
{
$variableName=$xmlTagName.$i;
$$variableName=$xmlFile->createElement($xmlTagName);
}
}
}
我同意其他意见,即您最好在此处使用数组
$properties = array();
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$properties['property' . $i] = $xmlFile->createElement ( $xmlTagName );
}
}
}
var_dump($properties);
$properties=array();
foreach($xmlTagName作为$xmlKey=>$xmlTagName)
{
如果($xmlTagName==“属性”)
{
对于($i=0;$i<4;$i++)
{
$properties['property'.$i]=$xmlFile->createElement($xmlTagName);
}
}
}
var_dump($properties);
如果设置为使用变量
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$variableName = $xmlTagName . $i;
$$variableName = $xmlFile->createElement ( $xmlTagName );
}
}
}
foreach($xmlTagNames作为$xmlKey=>$xmlTagName)
{
如果($xmlTagName==“属性”)
{
对于($i=0;$i<4;$i++)
{
$variableName=$xmlTagName.$i;
$$variableName=$xmlFile->createElement($xmlTagName);
}
}
}
我同意其他意见,即您最好在此处使用数组
$properties = array();
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$properties['property' . $i] = $xmlFile->createElement ( $xmlTagName );
}
}
}
var_dump($properties);
$properties=array();
foreach($xmlTagName作为$xmlKey=>$xmlTagName)
{
如果($xmlTagName==“属性”)
{
对于($i=0;$i<4;$i++)
{
$properties['property'.$i]=$xmlFile->createElement($xmlTagName);
}
}
}
var_dump($properties);
如果设置为使用变量
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$variableName = $xmlTagName . $i;
$$variableName = $xmlFile->createElement ( $xmlTagName );
}
}
}
foreach($xmlTagNames作为$xmlKey=>$xmlTagName)
{
如果($xmlTagName==“属性”)
{
对于($i=0;$i<4;$i++)
{
$variableName=$xmlTagName.$i;
$$variableName=$xmlFile->createElement($xmlTagName);
}
}
}
我同意其他意见,即您最好在此处使用数组
$properties = array();
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$properties['property' . $i] = $xmlFile->createElement ( $xmlTagName );
}
}
}
var_dump($properties);
$properties=array();
foreach($xmlTagName作为$xmlKey=>$xmlTagName)
{
如果($xmlTagName==“属性”)
{
对于($i=0;$i<4;$i++)
{
$properties['property'.$i]=$xmlFile->createElement($xmlTagName);
}
}
}
var_dump($properties);
如果设置为使用变量
foreach ( $xmlTagNames as $xmlKey => $xmlTagName )
{
if ($xmlTagName == "property")
{
for($i = 0; $i < 4; $i ++)
{
$variableName = $xmlTagName . $i;
$$variableName = $xmlFile->createElement ( $xmlTagName );
}
}
}
foreach($xmlTagNames作为$xmlKey=>$xmlTagName)
{
如果($xmlTagName==“属性”)
{
对于($i=0;$i<4;$i++)
{
$variableName=$xmlTagName.$i;
$$variableName=$xmlFile->createElement($xmlTagName);
}
}
}
这就是数组的用途。几乎每当你认为需要变量时(在手册中查找该术语),你实际上需要数组(也要查找)。是的,真的。这就是数组的用途。几乎每当你认为你需要变量时(在手册中查找该术语),你实际上需要数组(也要查找)。是的,真的。这就是数组的用途。几乎每当你认为你需要变量时(在手册中查找该术语),你实际上需要数组(也要查找)。是的,真的。这就是数组的用途。几乎每当你认为你需要变量时(在手册中查找该术语),你实际上需要数组(也要查找)。是的,真的。不需要双数组,因为$xmltangame
的值在$properties[$xmltangame][$i]
中始终是$properties[$xmltangame][$i]
中的$xmltangame
的“property”值。不需要双数组,由于$xmlTagName
的值在$properties[$xmlTagName][$i]
中始终是$property”
。无需使用双数组,因为$xmlTagName
的值在$properties[$xmlTagName][$i]
中始终是“property”
。您能在运行时更改变量的名称吗?还是我理解错了?您能在运行时更改变量的名称吗?还是我理解错了?您能在运行时更改变量的名称吗?还是我理解错了?您能在运行时更改变量的名称吗?还是我理解错了这个问题?