Qwibble
Members
-
Joined
-
Last visited
Reputation Activity
-
Qwibble got a reaction from smoothonline in Am I wrong to charge this muchAhh, such a simple piece of advice requested, and your all arguing. What is the world coming to..
-
Ok so welcome to this tutorial im gonna explain some about what an array is and how you can use them in php to your advantage. Im sure everyone here has heard the word array since there used in almost ever programming language and at the end of this tutorial you will know why.An array in simple terms is like a variable but can hold unlimited values so basicly you could have 1000 different values in an array lol though you prob would not need that much. But anyways imma show you a variable below that holds the value Cat then imma show you an array which holds a few different values.
$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