canadian_angel Posted June 15, 2010 Share Posted June 15, 2010 <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>My Books and Chapters</title> </head> <body> <?php // Script 7.4 - books.php // Address error handling. ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); // Create the first array. $phpvqs = array (1 => 'Getting Started', 'Variables', 'HTML Forms and PHP', 'Using Numbers'); // Create the second array. $phpadv = array (1 => 'Advanced PHP Programming', 'Object-Oriented Programming ', 'Databases', 'Security'); // Create the third array. $phpmysql = array (1 => 'Introduction to PHP', 'Programming with PHP', 'Introduction to SQL and MySQL'); // Create the multidimentional array. $books = array ( 'PHP VQS' => $phpvqs, 'PHP Advanced VQP' => $phpadv, 'PHP and MySQL VQP' => $phpmysql ); // Print out some values. print "<p>The third chapter of my first book is <i>{$books['PHP VQS'][3]}</i>.</p>"; print "<p>The first chapter of my second book is <i>{$books['PHP Advanced VQP'][1]}</i>.</p>"; print "<p>The fourth chapter of my fourth book is <i>{$books['PHP and MYSQL VQP'][4]}</i>.</p>"; // See what happens with foreach. foreach ($books as $key => $value) { print "<p>$key: $value</p>\n;"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/204810-i-know-i-did-it-right-but-it-doesnt-display-properly-help/ Share on other sites More sharing options...
Alex Posted June 15, 2010 Share Posted June 15, 2010 You didn't ask a question or tell us what your problem is. Quote Link to comment https://forums.phpfreaks.com/topic/204810-i-know-i-did-it-right-but-it-doesnt-display-properly-help/#findComment-1072233 Share on other sites More sharing options...
canadian_angel Posted June 15, 2010 Author Share Posted June 15, 2010 Sorry, It doesn't display a title for the fourth book and I can't figure out why. The third chapter of my first book is HTML Forms and PHP. The first chapter of my second book is Advanced PHP Programming. The fourth chapter of my fourth book is . PHP VQS: Array ; PHP Advanced VQP: Array ; PHP and MySQL VQP: Array Quote Link to comment https://forums.phpfreaks.com/topic/204810-i-know-i-did-it-right-but-it-doesnt-display-properly-help/#findComment-1072234 Share on other sites More sharing options...
phpchamps Posted June 15, 2010 Share Posted June 15, 2010 replace your foreach with the below code :- foreach ($books as $key => $value) { echo "<b>$key</b>"; foreach($books[$key] as $k=>$v){ print "<p>$k: $v</p>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/204810-i-know-i-did-it-right-but-it-doesnt-display-properly-help/#findComment-1072235 Share on other sites More sharing options...
Alex Posted June 15, 2010 Share Posted June 15, 2010 Well that's because $books['PHP and MYSQL VQP'][4] doesn't exist. Look at your own array: $phpmysql = array (1 => 'Introduction to PHP', 'Programming with PHP', 'Introduction to SQL and MySQL'); Quote Link to comment https://forums.phpfreaks.com/topic/204810-i-know-i-did-it-right-but-it-doesnt-display-properly-help/#findComment-1072236 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.