Jump to content

[SOLVED] Functions in arrays


scottybwoy

Recommended Posts

Is it possible to put functions in an array?

 

i.e.

if (tep_db_num_rows($filterlist_query) > 1) {
      $info_box_contents[] = array( array('text' => tep_draw_form('filter', FILENAME_DEFAULT, 'get')

        																						if (isset($HTTP_GET_VARS['manufacturers_id'])) {
																					          echo tep_draw_hidden_field('manufacturers_id', $HTTP_GET_VARS['manufacturers_id']);
																					          $options = array(array('id' => '', 'text' => TEXT_ALL_CATEGORIES));
																					        } else {
																					          echo tep_draw_hidden_field('cPath', $cPath);
																					          $options = array(array('id' => '', 'text' => TEXT_ALL_MANUFACTURERS));
																					        }

        																						echo tep_draw_hidden_field('sort', $HTTP_GET_VARS['sort']);

																					        while ($filterlist = tep_db_fetch_array($filterlist_query)) {
																					          $options[] = array('id' => $filterlist['id'], 'text' => $filterlist['name']);
																					        }

																					        echo tep_draw_pull_down_menu('filter_id', $options, (isset($HTTP_GET_VARS['filter_id']) ? $HTTP_GET_VARS['filter_id'] : ''), 'onchange="this.form.submit()"');
																					        echo '</form>';
																					      },
																	array('text' => "<label for='pfrom' class='fieldKey'>" . Cost . "</label>" . 
    																							echo tep_draw_input_field('pfrom', ENTRY_PRICE_FROM, 'class="fieldValue"') . 
    																							echo tep_draw_input_field('pto', ENTRY_PRICE_TO, 'class="fieldValue"'))),
    	};
	}

 

Link to comment
https://forums.phpfreaks.com/topic/131219-solved-functions-in-arrays/
Share on other sites

Sorry,  I'm editing some code thats in my OsCommerce site, and it uses its own templating engine that uses arrays to lay sections out.  What it is doing is choosing one part of data or another to go in the array cell.  Thats why I want the If statements in there.  Sorry I meant If statements not functions.  But it doesn't seem to like it.

 

Any ideas of ways around it?

$array = array('SomeKey' => func());

 

 

Or to answer your new question:

 

$array = array();

if() {

    $array['SomeKey'] = "something";

}

else {

    $array['SomeKey'] = "something else";

}

 

 

Or, this might work (untested, but theoretical):

 

$array = array(

    'SomeKey' => (<some condition) ? "something" : "something else",

);

 

Doubt that will work though.

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.