Jump to content

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


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

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.