Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

TUTORIAL: What are arrays and how to use them in php

Featured Replies

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 


Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.