I apologize in advance because I am very new to programming and am in a rush to get this complete as I am running on a deadline, this is also my first time using this webpage or in fact any forum.
I am required to create a simple array and loop in PHP that stores and prints the name of 3 tennis players.
My code is as follows:
html>
<head>
<title>Tennis Players Array</title>
</head>
<body>
<form action="" method="POST">
<input type="text" name="name">
<input type="submit" value = "submit">
</form>
<p>
<?php
$request = $_SERVER['REQUEST_METHOD'];
$name = $_POST['name'];
if ($request == 'GET')
{
// Do Nothing
}
else if ($request == 'POST')
{
$TennisPlayers = array("Roger Federer", "Rafael Nadal", "Novak Djokovic");
echo $TennisPlayers;
}
?>
</p>
</body>
</html>
I am getting an error when I run the code:
"Notice: Array to string conversion in C:\xampp\htdocs\Problem3\ProblemThree.php on line 19"
Line 19 is
echo $TennisPlayers;
And this is likely not going to be the only error once this one is corrected.
Look, I understand you aren't going to give me the direct answer to this and I appreciate that although I would really like some assistance in getting this to work. P.S Sorry for such a rookie question. Thank You! :)
array
asstring
that why you getting this error. If you want to printarray
than usedprint_r($array);
orvar_dump($array);