Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP 5 array and String Offsets

Status
Not open for further replies.

eiffel76

Programmer
Nov 7, 2006
7
US
Greetings,

I have an array to output a dropdown menu from a database that fails with the error "Cannot use string offset as an array". I'm using PHP 5 and I'm not sure how to change the function to be compatible.

Here's the string:
function tep_get_source_list($name, $show_other = false, $selected = '', $parameters = '')

"$show_other = false" is the offender. The intent is to have a dropdown menu where people can select which search engine they came from, or choose "other" to enter the information into a text field.

Here's the code:

function tep_get_source_list($name, $show_other = false, $selected = '', $parameters = '') {

$sources_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));
$sources = tep_get_sources();

for ($i=0, $n=sizeof($sources); $i<$n; $i++) {
$sources_array[] = array('id' => $sources[$i]['sources_id'], 'text' => $sources[$i]['sources_name']);
}

if ($show_other == 'true') {
$sources_array[] = array('id' => '9999', 'text' => PULL_DOWN_OTHER);
}

return tep_draw_pull_down_menu($name, $sources_array, $selected, $parameters);
}

Help is much apreciated
 
It's: $show_other = false

When it's removed, no error appears.
 
So when this line reads:

[tt]function tep_get_source_list($name, $show_other = false, $selected = '', $parameters = '') {[/tt]

you get the error but when it reads:

[tt]function tep_get_source_list($name, $show_other, $selected = '', $parameters = '') {[/tt]

it does not?



Want the best answers? Ask the best questions! TANSTAAFL!
 
There's no error when it reads:

Code:
function tep_get_source_list($name, $selected = '', $parameters = '') {

"$show_other = false" has to be completely removed (removing "= false" alone doesn't help).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top