Jump to content

function name must be a string? what function?


Go to solution Solved by Barand,

Recommended Posts

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>
  • Solution

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 by Barand
  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.