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
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?

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

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.