LemonStand Documentation

post_array_item

function post_array_item($array_name, $var, $default = null)

Returns an element with name specified in the second parameter from the array which name is specified in the first parameter from the $_POST array. If the array or the element is not found, returns default value, specified in the third parameter. This function is useful for form processing, when post values are grouped into arrays.

Parameters

  • $array_name - string. Specifies the array name.
  • $var - string. Specifies POST element name to return.
  • $default - mixed, default NULL. Specifies a default element value.

Return value

Returns mixed value.

Examples

Use this function when you need to access elements of array data in the $_POST array. For example, if you have the following input elements declared on the page:

<input type="checkbox" name="home_features[pool]" value="1" />
<input type="checkbox" name="home_features[lake_access]" value="1" />

you can access the posted values with the following code:

Lake access: <?= post_array_item('home_features', 'pool') ? 'yes' : 'no' ?>

Next: LemonStand front-end JavaScript Framework
Previous: post
Return to Reference