kamaboko 1 Posted August 28, 2014 Report Share Posted August 28, 2014 Hello, I've coded up the exercises for Chapter 7, in particular, the one regarding "Larry Ullman's Books". When I run it, I get an Array to String conversion error message. I thought maybe I coded something wrong, so I downloaded the code from this site to double check it. I get the same error. Could this be a PHP version problem? I'm using 5.5.12 with Apache version 2.4.9. Thanks, K Quote Link to post Share on other sites
HartleySan 826 Posted August 28, 2014 Report Share Posted August 28, 2014 What line is the error on, and what is the corresponding line of code? Quote Link to post Share on other sites
ailime 0 Posted August 19, 2015 Report Share Posted August 19, 2015 the foreach loop on page 166 doesn't work. Quote Link to post Share on other sites
Larry 428 Posted August 20, 2015 Report Share Posted August 20, 2015 Ailime, please provide way more details: What specific script are you running? (Or the specific code) What version of PHP are you using? What specific error message are you seeing? Just saying the foreach loop doesn't work isn't really useful (e.g., I know it worked when I wrote the book). Quote Link to post Share on other sites
ailime 0 Posted August 20, 2015 Report Share Posted August 20, 2015 Mr. Ullman Thank you for your quick reply. I am referring to code on chapter 7, page 166. It says you can use foreach loop to iterate through the $books array. The code for the loop is: foreach ($books as $key => $value){print "<p>$key: $value</p>\n";} I've checked the code several times. I even used the downloaded code. The error it throws is array to string conversion in localhost/..... . I am using the latest apache and php version as I installed it only two weeks ago. Quote Link to post Share on other sites
ailime 0 Posted August 20, 2015 Report Share Posted August 20, 2015 One more thing. The error is linked to the code line where print occurs. Quote Link to post Share on other sites
Larry 428 Posted August 22, 2015 Report Share Posted August 22, 2015 You didn't say what version of PHP you're using, but I assume this issue is caused by that. If you look at my image in the book (A, on page 166), you'll see "Array" is being printed by the loop. This is because you cannot print an array by just referencing the array name. On my version of PHP when I wrote the book, PHP just printed "Array". Your version and configuration is apparently printing an error. That's no surprise. However, the first tip on page 167, and figure B, shows how you can write the loop to access each book AND each chapter. Quote Link to post Share on other sites
ailime 0 Posted August 22, 2015 Report Share Posted August 22, 2015 It's version 5.5.27 according to phpinfo.php. Quote Link to post Share on other sites
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.
Note: Your post will require moderator approval before it will be visible.