PHP使函数中的变量递增.该函数在forloop中运行.重置为0? [英] PHP increment a variable in a function. The function runs in a forloop. resets to 0?
本文介绍了PHP使函数中的变量递增.该函数在forloop中运行.重置为0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常简单的PHP函数,该函数在运行时始终返回值1.我需要将变量$ board的值增加到1,2,3,4,5,6,依此类推.在这里找不到错误?
Hi I have a very simple PHP function which when runs always returns the value of 1. I need to increment the value of the variable $board to 1,2,3,4,5,6 and so on. Cannot catch the error here ?
function poste() {
$board++;
echo $board;
global $sourcedir;
require_once($sourcedir . '/Subs-Post.php');
$msgoptions = array(
'id' => 0,
'body' => 'Welcome',
'subject' => 'Welcome To The Boards',
);
$topicoptions = array(
'id' => 0,
'board' => $board,
'poll' => null,
'lock_mode' => 0,
'sticky_mode' => 0,
'mark_as_read' => false,
);
$posteroptions = array(
'update_post_count' => 1,
);
createPost($msgoptions, $topicoptions, $posteroptions);
}
for($board = 1; $board <= 3; $board++ ){
$board++;
echo $board;
poste();
}
for
循环中的
推荐答案
$board
与您的函数不同.函数是子程序",因此它是一个不同的变量.
$board
in the for
loop is not the same in your function. function is "subprogram" so it's a different variable.
使用类似poste($board)
的东西.
function poste($board) {
$board++;
echo $board;
global $sourcedir;
require_once($sourcedir . '/Subs-Post.php');
$msgoptions = array(
'id' => 0,
'body' => 'Welcome',
'subject' => 'Welcome To The Boards',
);
$topicoptions = array(
'id' => 0,
'board' => $board,
'poll' => null,
'lock_mode' => 0,
'sticky_mode' => 0,
'mark_as_read' => false,
);
$posteroptions = array(
'update_post_count' => 1,
);
createPost($msgoptions, $topicoptions, $posteroptions);
}
for($board = 1; $board <= 3; $board++ ){
$board++;
echo $board;
poste($board);
}
这应该有效.
这篇关于PHP使函数中的变量递增.该函数在forloop中运行.重置为0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文