$test = "Cat";
Ok so as you can see the variable test holds the value of cat but say you want it to hold a value of dog to you can do this but you would have to right it out like this.
$test = "Cat"; $test .="Dog"; $test .="Rabbit";
Above we have our main variable $test now in lame terms you cant use the same variable more then once on a page
but if you were to put the Dot in front of the Equal sign then this would not be using it more then once cause it would connect the variables together and basicly make it just once varable that would hold
Cat,Dog,Rabbit.This is where an array would be handy lets create one now to hold those same values.
$test = array('Cat','Dog','Rabbit');
see thats alot easier huh well you can also give each one of those animals a name like this
$test['my_array'] = array( 'FRED' => 'Cat', 'BILLY' => 'Dog', 'CARROT' => 'Rabbit' );
And to echo out a certain value like cat from the array do this
echo "".$test['my_array']['FRED']."";
Ok so now that we got a few basics down pat lets get into the heavy lifting so to speak lol ok so we are gonna test if a certain value is in an array if it is it will output Value is in array other wise it will output Value not in array
<?php
$input = $_POST['test'];
$test = array('cat','dog',rabbit);
if(isset($_POST['submit'])){
if(in_array($input,$test)){
echo "Value is in array";
}else{
echo "Value not in array";
}
}
echo"
<form method=\"POST\" action=\"test.php\">
<input type=\"text\" name=\"test\">
<input type=\"submit\" name=\"submit\" value=\"Test\">
</form>
";
?>
So this is a short tutorial on arrays hope
you enjoy and if you enjoy this post
feel free to give me a +1
Help
















