@annie and @sherlyk Good examples. That is single dimensional associated array. Try multi dimensional array.
@annie and @sherlyk Good examples. That is single dimensional associated array. Try multi dimensional array.
Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
http://php.flashwebhost.com/sibichan/Day-6/day_6_array_1.php
PHP Code:
<?php
$company = array();
$company['website'] ='Buyscripts.in';
$company['script'] ='vShare Youtube Clone';
$company['price'] =10;
echo '<pre>';
print_r ($company);
echo '<pre>';
echo $company['website'] . ' provide ' . strtoupper($company['script']) . ' script for $ ' . $company['price'];
Last edited by Vahaa11; 05-15-2014 at 05:44 AM.
Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
http://php.flashwebhost.com/sherly/Laptops.php
Code:<?php $lapTops = array(); $lapTop1 = array(); $lapTop1['name'] = 'Toshiba Laptop'; $lapTop1['price'] = 25000; $lapTop1['available'] = 'yes'; $lapTop1['supplier'] = 'Toshiba Company'; $lapTop2 = array(); $lapTop2['name'] = 'Acer Aspire'; $lapTop2['price'] = 40000; $lapTop2['available'] = 'yes'; $lapTop2['supplier'] = 'Acer Intel Core'; $lapTop3 = array(); $lapTop3['name'] = 'Apple MacBook Air'; $lapTop3['price'] = 38000; $lapTop3['available'] = 'no'; $lapTop3['supplier'] = 'Apple Intel Core'; $lapTops[] = $lapTop1; $lapTops[] = $lapTop2; $lapTops[] = $lapTop3; /* // Lets print_r() the array echo '<pre>'; print_r($lapTops); echo '</pre>'; */ // Lets list laptops more user friendly way using lighter and easier echo '<h1>Menu</h1>'; foreach ($lapTops as $lapTop) { echo '<hr>'; echo '<b>Name:</b> ' . $lapTop['name'] . '<br>'; echo '<b>Price:</b> Rs: ' . $lapTop['price'] . '/-<br>'; echo '<b>Supplier:</b> ' . $lapTop['supplier'] . '<br>'; echo '<b>In Stock:</b> ' . $lapTop['available'] . '<br>'; if ($lapTop['available'] == 'yes') { echo '<p>Product in stock, buy it soon.</p>'; } } echo '<hr>'; // <hr> draw a line in your browser, thanks to HTML.
http://php.flashwebhost.com/annie/array.php
Code:<?php $refrigerators = array(); $refrigerator1 = array(); $refrigerator1[ 'name' ] = 'Whirlpool Ice magic Royal'; $refrigerator1[ 'price' ] = 9500; $refrigerator1[ 'available' ] = 'yes'; $refrigerator1[ 'rating' ] = '3 Star Energy Rating'; $refrigerator1[ 'supplier' ] = 'Bismi Home Appliance'; $refrigerator2 = array(); $refrigerator2[ 'name' ] = 'Whirlpool Star Single Door'; $refrigerator2[ 'price' ] = 12500; $refrigerator2[ 'available' ] = 'no'; $refrigerator2[ 'rating' ] = 'Five Star'; $refrigerator2[ 'supplier' ] = 'White Mart '; $refrigerator3 = array(); $refrigerator3[ 'name' ] = 'Whirlpool Double Door Frost '; $refrigerator3[ 'price' ] = 25000; $refrigerator3[ 'available' ] = 'yes'; $refrigerator3[ 'rating' ] = 'Five Star'; $refrigerator3[ 'supplier' ] = 'Nadilath G-Mart '; $refrigerator4 = array(); $refrigerator4[ 'name' ] = 'Whirlpool Multi Door Royal'; $refrigerator4[ 'price' ] = 35000; $refrigerator4[ 'available' ] = 'yes'; $refrigerator4[ 'rating' ] = 'Five Star'; $refrigerator4[ 'supplier' ] = 'QRS '; $refrigerators[] = $refrigerator1; $refrigerators[] = $refrigerator2; $refrigerators[] = $refrigerator3; $refrigerators[] = $refrigerator4; echo '<h1>Buy Refrigerator Online</h1>'; foreach ($refrigerators as $refrigerator) { echo '<hr>'; echo '<b> Name: </b> ' . $refrigerator[ 'name' ] . '<br>'; echo '<b> Price: </b> Rs: ' . $refrigerator[ 'price' ] . '/-<br>'; echo '<b> In Stock: </b> ' . $refrigerator['availabile' ] . '<br>'; echo '<b> Rating: </b> ' . $refrigerator[ 'rating' ] . '<br>'; echo '<b> Supplier: </b> ' . $refrigerator[ 'supplier' ] . '<br>'; If ($refrigerator['available'] == 'no') { echo '<p>This Product is out of stock.</p>'; } If ($refrigerator['available'] == 'yes') { echo '<p>Product in stock, buy it soon.</p>'; } } echo '<hr>';
http://php.flashwebhost.com/mini/array_1.php
Code:<?php $mobile = array(); $mobile['Name'] = 'Reliance Mobile Phone'; $mobile['Price'] = 5000; $mobile['Color'] = 'yellow'; $mobile ['Sim'] = 'duel'; $mobile ['Camera'] = '8mp'; echo '<pre>'; print_r($mobile); echo '</pre>'; echo '<h1>Product Details</h1>'; echo ' <b>Name:</b> ' . $mobile['Name'] . '<br>'; echo ' <b>Price:</b>Rs: ' . $mobile['Price'] . '/-<br>'; echo ' <b>Color:</b> ' . $mobile['Color'] . '<br>'; echo ' <b>Sim:</b> ' . $mobile ['Sim'] . '<br>'; echo ' <b>Camera:</b> ' . $mobile ['Camera'] . '<br>';
Last edited by minisoji; 05-15-2014 at 09:26 AM.
http://php.flashwebhost.com/sibichan...ray_2_eg_1.php
PHP Code:
<?php
$shoes = array();
$shoes1 = array();
$shoes1 ['brand'] = 'Puma';
$shoes1 ['size'] = '7';
$shoes1 ['color'] = 'Red';
$shoes1 ['available'] = 'No';
$shoes2 = array();
$shoes2 ['brand'] = 'Nike';
$shoes2 ['size'] = 'Puma';
$shoes2 ['color'] = 'Blue';
$shoes2 ['available'] = 'Yes';
$shoes3 =array ();
$shoes3 ['brand'] = 'Reebok';
$shoes3 ['size'] = 'Puma';
$shoes3 ['color'] = 'Black';
$shoes3 ['available'] = 'Yes';
$shoes4 = array();
$shoes4 ['brand'] = 'Adidas';
$shoes4 ['size'] = 'Puma';
$shoes4 ['color'] = 'White';
$shoes4 ['available'] = 'Yes';
$shoes[] = $shoes1;
$shoes[] = $shoes2;
$shoes[] = $shoes3;
$shoes[] = $shoes4;
foreach ($shoes as $shoe) {
echo ' Brand : ' . $shoe['brand'] . '<br>';
echo ' Size : ' . $shoe['size'] . '<br>';
echo ' Color : ' . $shoe['color'] . '<br>';
echo ' Available : ' . $shoe['available'] . '<br>';
if ($shoe ['available'] == 'Yes'){
echo '<a href="">Click here</a> to order your ' . $shoe['brand'] . ' shoe ' ;
}
if ($shoe ['color'] == 'Red') {
echo '<font size="" color="#ff0000"> ' . $shoe['color'] .'</font>' . ' color puma shoe - out of stock';
}
echo '<hr>';
}
Last edited by Vahaa11; 05-15-2014 at 08:54 AM.
http://php.flashwebhost.com/vineesh/..._6_array_2.php
PHP Code:<?php
$timeTables = array();
$timeTable1 = array();
$timeTable1[day] = 'monday';
$timeTable1[teacher] = 'murali';
$timeTable1[subject] = 'english';
$timeTable1[period] = 'first period';
$timeTable1[availability] = 'present';
$timeTable2 = array();
$timeTable2[day] = 'tuesday';
$timeTable2[teacher] = 'chandrika';
$timeTable2[subject] = 'chemistry';
$timeTable2[period] = 'second period';
$timeTable2[availability] = 'present';
$timeTable3 = array();
$timeTable3[day] = 'wednesday';
$timeTable3[teacher] = 'alice';
$timeTable3[subject] = 'biology';
$timeTable3[period] = 'third period';
$timeTable3[availability] = 'absent';
$timeTables[] = $timeTable1;
$timeTables[] = $timeTable2;
$timeTables[] = $timeTable3;
echo '<h2><font=color:red;>Class info: </font> </h2>';
foreach ($timeTables as $timeTable) {
echo '<b> <font color=blue>Day: </font></b>' . ucwords($timeTable[day]) . '<br>';
echo '<b> <font color=blue>Name of the Teacher: </font></b>' . ucwords($timeTable[teacher]) . '<br>';
echo '<b> <font color=blue>Subject:</font></b> ' . ucwords($timeTable[subject]) . '<br>';
echo '<b> <font color=blue>Period: </font></b> ' . ucwords($timeTable[period]) . '<br>';
if ($timeTable[availability] == 'present') {
echo '<p>Students, teacher is on the way, you may go to your classes.</p>';
} if ($timeTable[availability] == 'absent') {
echo '<p>Heyy.. teacher is absent today, you may go home :) </p>';
}
}
Bookmarks