PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

HOW TO VIEW ARRAYS

You can view the structure if an array using either one of two functions. These are print_r() and var_dump(). These are further explained below:

Assume we have an array created as follows:

$fruits=array('apple', 'banana', 'orange', 'peach');

View Using print_r():

echo "<pre>";
print_r($fruits);
echo "</pre>";

will output to your screen:

Array
(
[0] => apple
[1] => banana
[2] => orange
[3] => peach
)

Note that if you omit <pre> and </pre>, you will get the output in a long line.

View Using var_dump():

echo "<pre>";
var_dump($fruits);
echo "</pre>";

will output to your screen:

array(4) {
[0]=>
string(5) "apple"
[1]=>
string(6) "banana"
[2]=>
string(6) "orange"
[3]=>
string(5) "peach"
}

Note that if you omit <pre> and </pre>, you will get the output in a long line. You would have noticed that the var_dump() gives you a lot more information than the print_r().

The (4) next to the word array tells you that there are 4 elements in this array. The elements keys and values are then listed one below the other. For each of the elements, the number between [ ] is the key, string states that the value is a string, the number between ( ) after the word string tells you how many characters that string contains. The actual value is between " ".

See also:

What Are Arrays?
How To Create Arrays
How To Modify Arrays
Array arsort() Function
Array asort() Function
Array rsort() Function
Array sort() Function
Array ksort() Function
Array krsort() Function
Array Echo
Array list() Function
Manual Array Iteration
Array count() & sizeof() Function




Home | Privacy Policy | Terms Of Use | Contact Us