this works .. and its basically all your code ... BUT you were missing some closing semi colons and you CANNOT redeclare a base php function like count ... just use it ...
CODE
<html>
<head>
<title>CREATING ARRAY AND FINDING OUT THE SIZE</title>
</head>
<body>
<ul> <!-- start main ul -->
<?php
$color = array("red", "orange", "yellow", "green", "blue", "indigo", "violet");
foreach($color as $value){
echo "<li>My color is = $value</li>";
}
?>
<ul> <!-- start nested ul -->
<?php echo "<li><b>Total Elements In Array = " . count($color) . "</li>"; ?>
</ul> <!-- end nested ul -->
</ul> <!-- end main ul -->
</body>
</html>
and if your bored like i was take a peak at this ...
CODE
<?php
error_reporting(E_ALL);
session_start();
// define out base array
$color = isset($_SESSION['color_array']) ? $_SESSION['color_array'] : array("red", "orange", "yellow", "green", "blue", "indigo", "violet");
// if the user submitted something we deal with it
if (isset($_POST['addcolor']) && $_POST['addcolor'] != "") {
// add user color
$color[] = $_POST['addcolor'];
// make sure there are no duplicates
$color = array_unique($color);
// user wants to remove color
} else if (isset($_GET['removecolor']) && isset($_GET['key'])) {
if (isset($color[$_GET['key']])) {
unset($color[$_GET['key']]);
}
} else if (isset($_GET['resetarray'])) {
if ($_GET['resetarray'] == "true") {
$_SESSION['color_array'] = $color = array("red", "orange", "yellow", "green", "blue", "indigo", "violet");
}
}
// define the session variable
$_SESSION['color_array'] = $color;
?>
<html>
<head>
<title>CREATING ARRAY AND FINDING OUT THE SIZE</title>
<style type="text/css">
a, a:visited { color: #EE4000; font-size: 10px; }
a:hover, a:visited:hover { color: #8B2500; }
#resetlink, #resetlink:visited { color: #008080; font-size: 14px; }
#resetlink:hover, #resetlink:visited:hover { color: #2F4F4F; font-size: 14px; }
</style>
</head>
<body>
<ul> <!-- start main ul -->
<?php
foreach($color as $key => $value){
echo "<li>My color is = $value <a href='?removecolor=$value&key=$key'>^remove this color?^</a></li>";
}
?>
<ul> <!-- start nested ul -->
<?php echo "<li><b style='color:#FF0000'>Total Elements In Array = " . count($color) . "</b></li>"; ?>
<li>
<b style='color:#488214'>Would you like to add a color? What color = </b>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" style="display:inline">
<input type="text" value="" name="addcolor">
<input type="submit" value="Add Color"/>
</form>
</li>
<li>
<a id="resetlink" href="?resetarray=true">Reset array to default?</a>
</li>
</ul> <!-- end nested ul -->
</ul> <!-- end main ul -->
</body>
</html>
This post has been edited by RPGonzo: 5 Nov, 2009 - 11:01 AM