dhmyers82 Posted February 9, 2015 Share Posted February 9, 2015 I keep getting the following error: Fatal error: Function name must be a string in /home/dmyers53/public_html/Projects/Chisese_Zodiac_for_loop.php on line 34 I dont have a function named, where am I going wrong? <body> <img src="images/rat.jpg"></img><!--test the source. WORKS--> <?php error_reporting(E_ALL); ini_set('display_errors', 'on'); echo "<p>This line works</p>\n";//yes it does $zodiacPictures = array( "images/rat.jpg", "images/ox.jpg", "images/tiger.jpg", "images/rabbit.jpg", "images/dragon.jpg", "images/snake.jpg", "images/horse.jpg", "images/sheep.jpg", "images/monkey.jpg", "images/rooster.jpg", "images/dog.jpg", "images/pig.jpg"); for ($imgCounter = 0; $imgCounter <= 12; ++$imgCounter){ echo '<img src="' . $zodiacPictures($imgCounter) . '"></img>';// line 34 } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/294485-function-name-must-be-a-string-what-function/ Share on other sites More sharing options...
Solution Barand Posted February 9, 2015 Solution Share Posted February 9, 2015 (edited) This function $zodiacPictures($imgCounter) You need [..] for array indexes. (..) is for functions [edit] Using foreach() would be easier foreach ($zodiacPictures as $src){ echo '<img src="' . $src . '" />'; } and there are no </img> tags Edited February 9, 2015 by Barand 1 Quote Link to comment https://forums.phpfreaks.com/topic/294485-function-name-must-be-a-string-what-function/#findComment-1505281 Share on other sites More sharing options...
cyberRobot Posted February 9, 2015 Share Posted February 9, 2015 Try changing this echo '<img src="' . $zodiacPictures($imgCounter) . '"></img>'; To this echo '<img src="' . $zodiacPictures[$imgCounter] . '"></img>'; Note the square brackets around $imgCounter. 1 Quote Link to comment https://forums.phpfreaks.com/topic/294485-function-name-must-be-a-string-what-function/#findComment-1505283 Share on other sites More sharing options...
dhmyers82 Posted February 9, 2015 Author Share Posted February 9, 2015 (edited) Thank you, PHP is making me want to throw my computer out the window... Its for homework so it has to be a "for". When Im done with this I get to change it to a "while". Im so excited Edited February 9, 2015 by dhmyers82 Quote Link to comment https://forums.phpfreaks.com/topic/294485-function-name-must-be-a-string-what-function/#findComment-1505284 Share on other sites More sharing options...
Barand Posted February 9, 2015 Share Posted February 9, 2015 Have a go at VB. You'll want to throw yourself out of the window 1 Quote Link to comment https://forums.phpfreaks.com/topic/294485-function-name-must-be-a-string-what-function/#findComment-1505285 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.