我刚刚开始在工作中学习PHP,并被要求以大写形式输出Alphabet,然后以小写形式输出.这需要在页面上重复10次.
这是我已经放在一起的代码,但是必须有更简单的方法来重复这个,而不是只复制和粘贴它10次.
<?php
for ($i=65; $i<=90; $i++) {
$Letter = chr($i);
print $Letter .", ";
}
for ($i=97; $i<=122; $i++) {
$Letter = chr($i);
print $Letter .", ";
}
?>
Run Code Online (Sandbox Code Playgroud)
有人告诉我,For循环最好用,而不是foreach循环.
我做了以下'foreach',我需要循环10次然后停止.我不能使用for命令.
<?php
$x=array("Seb","Ginna","Shane","Guy","Jackie","Frances","John","Alec","Jon","Sam","Chris","Paula");
foreach ($x as $value)
{
echo $value . ",";
}
?>
Run Code Online (Sandbox Code Playgroud)
我使用的是这个:
<?php
$theNames = array('Seb', 'Ginna', 'Shane', 'Guy', 'Jackie', 'Frances', 'John', 'Alec', 'Jon', 'Sam', 'Chris', 'Paula');
$toOutput = implode(",", $theNames);
for ($i=0; $i < 10; $i++) {
print $toOutput."<br/>";
}
?>
Run Code Online (Sandbox Code Playgroud)
前面的代码按照我想要的方式工作,但是我需要它在foreach循环中工作
我想让我的sql将html表单中的信息发布到我的数据库中但是请继续:
( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: firstname in C:\wamp\www\insert.php on line 29
Call Stack
# Time Memory Function Location
1 0.0005 247624 {main}( ) ..\insert.php:0
Run Code Online (Sandbox Code Playgroud)
我使用的代码是:
<form action="insert.php" method="post">
Name: <input type="text" name="firstname">
<input type="submit" value="Submit">
</form>
<?php
// This is the connection to my database
$con = mysql_connect('127.0.0.1', 'shane', 'diamond89');
if (!$con){
die('Could not Connect: ' . mysql_error());
}
// This selects which database i want to connect to
$selected …Run Code Online (Sandbox Code Playgroud)