kamaboko Posted August 28, 2014 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 Link to comment Share on other sites More sharing options...
HartleySan Posted August 28, 2014 Share Posted August 28, 2014 What line is the error on, and what is the corresponding line of code? Link to comment Share on other sites More sharing options...
ailime Posted August 19, 2015 Share Posted August 19, 2015 the foreach loop on page 166 doesn't work. Link to comment Share on other sites More sharing options...
Larry Posted August 20, 2015 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). Link to comment Share on other sites More sharing options...
ailime Posted August 20, 2015 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. Link to comment Share on other sites More sharing options...
ailime Posted August 20, 2015 Share Posted August 20, 2015 One more thing. The error is linked to the code line where print occurs. Link to comment Share on other sites More sharing options...
Larry Posted August 22, 2015 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. Link to comment Share on other sites More sharing options...
ailime Posted August 22, 2015 Share Posted August 22, 2015 It's version 5.5.27 according to phpinfo.php. Link to comment Share on other sites More sharing options...
Recommended Posts