Explain why the curley braces was used in this php statment?

OSS

New member
I'm currenly learning PHP and I came upon an example on the book that I did't understand why they used the curley braces under the foreach functions.

here is a link to the book example on page 123

http://books.google.com/books?id=Zwzc4qUZnqMC&lpg=PA123&dq=loop%20has%20two%20statement%20within%20is%2C%20so%20curly%20braces%20enclose%20them&pg=PA122#v=onepage&q=loop%20has%20two%20statement%20within%20is,%20so%20curly%20braces%20enclose%20them&f=false


thank you all.


<?php



$chessboard = array(

array('r','n','b','k','q','b','n','r'),
array('p','p','p','p','p','p','p','p'),
array(' ',' ',' ',' ',' ',' ',' ',' '),
array(' ',' ',' ',' ',' ',' ',' ',' '),
array(' ',' ',' ',' ',' ',' ',' ',' '),
array(' ',' ',' ',' ',' ',' ',' ',' '),
array(' ',' ',' ',' ',' ',' ',' ',' '),
array(' ',' ',' ',' ',' ',' ',' ',' '),
array('P','P','P','P','P','P','P','P'),
array('R','N','B','K','Q','B','N','R'),);


echo "<pre>";

foreach ($chessboard as $row)
{


foreach ($row as $piece)

echo "$piece " ;
echo "<br>";

}
echo "</pre>";


echo $chessboard [9][4];


?>

<?php
in this example of array, the curley braces weren't used. please explain why they were used in the first example and not the 2nd.


<?php



$product = array(

'paper' => array(
'copier'=> " copier & multipurpose",
'inkject'=> " inkjet printer",
'laser '=> " laser printer",
'photo'=> " photo crap"),


'pens' => array( 'ball'=> " ball go away",
'hilite'=> " highlighters",
'marker'=> " Markers"),



'misc'=> array('tape'=>" sticky tape",

'glue'=> " adhesives",
'clips'=>" paperclip")



);


echo "<pre>";

foreach ( $product as $section=> $item)

foreach ($item as $key=>$value)



echo " $section:\t$key\t($value)<br>" ;


echo "</pre>";




?>
 
Back
Top