Jump to content

Parse error: syntax error, unexpected '[', expecting ')' in function


Go to solution Solved by Jacques1,

Recommended Posts

I have a single dimensional array of item characteristics called $item[ ], I get the above error when I try to define the functon parameters like this

function bread_crumb($item['id'], $dbc)

 

However when I change it to this the function works fine

$id = $item['id'];
function bread_crumb($id, $dbc)

 

Can you use an array to define a function's parameters and if you can how do you do it?

 

Thanks

  • Solution

I think you confuse function definitions and function calls. 

 

The parameters of a function definition have nothing to do with outside variables. They are generic placeholders which get concrete values when you call the function:

<?php

/*
 * This is a function definition; the parameter $name is a placeholder of the function.
 * It does not refer to any outside variable, even if there happens to be a variable
 * called $name as well.
 */
function hello($name)
{
	echo 'Hello, ' . $name . '.';
}

/*
 * This is a function call. This is when you pass concrete values to the parameters
 * and execute the function body.
 */
$you = 'floridaflatlander';
hello($you);
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.