请教一个php数组循环的问题,知道的大神指导一下!
<span><?phpechosetting_get('huoyanju_sm_name_1_htm');?><hr><?phpechosetting_get('huoy...
<span>
<?php echo setting_get('huoyanju_sm_name_1_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_2_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_3_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_4_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_5_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_5_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_5_htm');?><hr>
...............................................
</span>
这样一个类似的php,怎样写成一个数组
$arr=array(1=> 'PHP第一行的输出值' ,2=>'PHP第二行的输出值',3=>‘PHP第三行的输出值’等等自动加在后面);
if($method == 'GET') {
$setting['huoyanju_sm_name_1_htm'] = setting_get('huoyanju_sm_name_1_htm');
$setting['huoyanju_sm_name_2_htm'] = setting_get('huoyanju_sm_name_2_htm');
$setting['huoyanju_sm_name_3_htm'] = setting_get('huoyanju_sm_name_3_htm');
$setting['huoyanju_sm_name_4_htm'] = setting_get('huoyanju_sm_name_4_htm');
$setting['huoyanju_sm_name_5_htm'] = setting_get('huoyanju_sm_name_5_htm');
include _include(APP_PATH.'plugin/huoyanju_sm/setting.htm');
} else {
setting_set('huoyanju_sm_name_1_htm', param('huoyanju_sm_name_1_htm', '', FALSE));
setting_set('huoyanju_sm_name_2_htm', param('huoyanju_sm_name_2_htm', '', FALSE));
setting_set('huoyanju_sm_name_3_htm', param('huoyanju_sm_name_3_htm', '', FALSE));
setting_set('huoyanju_sm_name_4_htm', param('huoyanju_sm_name_4_htm', '', FALSE));
setting_set('huoyanju_sm_name_5_htm', param('huoyanju_sm_name_5_htm', '', FALSE));
message(0, '配置成功');
}
?>
如何写成无限循环的模式!
最好把意思也解释一下! 展开
<?php echo setting_get('huoyanju_sm_name_1_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_2_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_3_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_4_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_5_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_5_htm');?><hr>
<?php echo setting_get('huoyanju_sm_name_5_htm');?><hr>
...............................................
</span>
这样一个类似的php,怎样写成一个数组
$arr=array(1=> 'PHP第一行的输出值' ,2=>'PHP第二行的输出值',3=>‘PHP第三行的输出值’等等自动加在后面);
if($method == 'GET') {
$setting['huoyanju_sm_name_1_htm'] = setting_get('huoyanju_sm_name_1_htm');
$setting['huoyanju_sm_name_2_htm'] = setting_get('huoyanju_sm_name_2_htm');
$setting['huoyanju_sm_name_3_htm'] = setting_get('huoyanju_sm_name_3_htm');
$setting['huoyanju_sm_name_4_htm'] = setting_get('huoyanju_sm_name_4_htm');
$setting['huoyanju_sm_name_5_htm'] = setting_get('huoyanju_sm_name_5_htm');
include _include(APP_PATH.'plugin/huoyanju_sm/setting.htm');
} else {
setting_set('huoyanju_sm_name_1_htm', param('huoyanju_sm_name_1_htm', '', FALSE));
setting_set('huoyanju_sm_name_2_htm', param('huoyanju_sm_name_2_htm', '', FALSE));
setting_set('huoyanju_sm_name_3_htm', param('huoyanju_sm_name_3_htm', '', FALSE));
setting_set('huoyanju_sm_name_4_htm', param('huoyanju_sm_name_4_htm', '', FALSE));
setting_set('huoyanju_sm_name_5_htm', param('huoyanju_sm_name_5_htm', '', FALSE));
message(0, '配置成功');
}
?>
如何写成无限循环的模式!
最好把意思也解释一下! 展开
3个回答
展开全部
var $n=10;
if($method == 'GET') {
for($i=1;$i<$n;i++){
$tmp_name = "huoyanju_sm_name_".$i."_htm";
$setting[$tmp_name] = setting_get($tmp_name);//数组$setting 键值对是一样的值了
}
include _include(APP_PATH.'plugin/huoyanju_sm/setting.htm');
} else {
for($i=1;$i<$n;i++){
$tmp_name = "huoyanju_sm_name_".$i."_htm";
setting_set($tmp_name, param('$tmp_name', '', FALSE));
}
message(0, '配置成功');
}
不知道这样能否帮到你
<?php foreach ($setting as $v)
echo setting_get($v);
echo "<hr>";
}?>
展开全部
<?php
$s=1;
$n=1;
$arr=array();
while($s){
if($n>5){
#退出while无线循环
$s=0;
}
#生成$arr的数组元素,想生成多少个元素根据$n的大小来设置
$arr[$n]="huoyanju_sm_name_".$n."_htm";
$n++;
}
if($method == 'GET') {
foreach($arr as $k=>$v)
$setting[$v] = setting_get($v);
}
include _include(APP_PATH.'plugin/huoyanju_sm/setting.htm');
} else {
foreach($arr as $k=>$v)
setting_set($v, param($v,'',FALSE));
}
message(0, '配置成功');
}
?>
$s=1;
$n=1;
$arr=array();
while($s){
if($n>5){
#退出while无线循环
$s=0;
}
#生成$arr的数组元素,想生成多少个元素根据$n的大小来设置
$arr[$n]="huoyanju_sm_name_".$n."_htm";
$n++;
}
if($method == 'GET') {
foreach($arr as $k=>$v)
$setting[$v] = setting_get($v);
}
include _include(APP_PATH.'plugin/huoyanju_sm/setting.htm');
} else {
foreach($arr as $k=>$v)
setting_set($v, param($v,'',FALSE));
}
message(0, '配置成功');
}
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
提供思路,简单的for循环
$setting = array();
for($i=1;$i<=5;$i++){
$setting[$i] = setting_get('huoyanju_sm_name_'.$i.'_htm')
}
dump($setting);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询