# tablepress/3.4/libraries/vendor/PhpSpreadsheet/Calculation/LookupRef/Selection.php

TablePress – Tables in WordPress made easy, version 3.4. 52 lines.

- Page: https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Calculation/LookupRef/Selection.php
- Raw: https://pluginprobe.com/plugins/tablepress/3.4/raw/libraries/vendor/PhpSpreadsheet/Calculation/LookupRef/Selection.php
- Modified: 2025-12-16T10:47:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Calculation/LookupRef/Selection.php#L10-L20`.

```php
<?php

namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\LookupRef;

use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions;
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;

class Selection
{
	use ArrayEnabled;

	/**
	 * CHOOSE.
	 *
	 * Uses lookup_value to return a value from the list of value arguments.
	 * Use CHOOSE to select one of up to 254 values based on the lookup_value.
	 *
	 * Excel Function:
	 *        =CHOOSE(index_num, value1, [value2], ...)
	 *
	 * @param mixed $chosenEntry The entry to select from the list (indexed from 1)
	 * @param mixed ...$chooseArgs Data values
	 *
	 * @return mixed The selected value
	 */
	public static function choose($chosenEntry, ...$chooseArgs)
	{
		if (is_array($chosenEntry)) {
			return self::evaluateArrayArgumentsSubset([self::class, __FUNCTION__], 1, $chosenEntry, ...$chooseArgs);
		}

		$entryCount = count($chooseArgs) - 1;

		if (is_numeric($chosenEntry)) {
			--$chosenEntry;
		} else {
			return ExcelError::VALUE();
		}
		$chosenEntry = (int) floor($chosenEntry);
		if (($chosenEntry < 0) || ($chosenEntry > $entryCount)) {
			return ExcelError::VALUE();
		}

		if (is_array($chooseArgs[$chosenEntry])) {
			return Functions::flattenArray($chooseArgs[$chosenEntry]);
		}

		return $chooseArgs[$chosenEntry];
	}
}

```
