- Single Dimensional Array
- Multi Dimensional Array
$bookName = "Sample Book";
$bookAuthor = "Author\'s Name";
$bookPublished = "April 02, 2013";
$bookPublisher = "Sample Book Publisher";
But you can store above all values to a single array.
- Single Dimensional Arrays
Ex:
$book = array(
"Sample Book",
"Author's Name",
"April 02, 2013",
"Sample Book Publisher"
) //use a book array to store above values
echo "Book Name : " . $book[0]; // Print 1st element of the array
Another way of defining the Array. This is calling Associative Arrays.
$book = array(
'BookName' => "Sample Book",
'bookAuthor' => "Author\'s Name",
'bookPublished' => "April 02, 2013",
'bookPublisher => "Sample Book Publisher"
) //use a associative book array to store above values
echo "Book Name : " . $book['BookName']; // Print bookname element of the array
- Multi Dimensional Arrays
Multi dimensional array is an array within an array and nest within themselves.
Ex:
$books = array(
array("Book1", "Author 1", "April 01, 2013", "Publisher 1"),
array("Book2", "Author 2", "April 01, 2013", "Publisher 2"),
array("Book3", "Author 3", "April 01, 2013", "Publisher 3"),
array("Book4", "Author 4", "April 01, 2013", "Publisher 4")
) ;//use a books array to store 4 book values
echo "Book Name : " . $book[0][0]; // Print 1st element of the 1st Array; its "Book1"
No comments:
Post a Comment