# column()

{% code title="Example.php" %}

```php
<?php
use kim\present\utils\arrays\ArrayUtils;

$arrayUtils = ArrayUtils::from([
    ["any" => "first",  1, 2, 3],
    ["any" => "second", 4, 5, 6],
    ["any" => "third",  7, 8, 9]
]);

// Use "any" value in internal array as value of array
$arrayUtils->column("any");
// expected output: ["first", "second", "third"]


// Use 2nd value in internal array as value,
// Use "any" in internal array as key of array
$arrayUtils->column(1, "any");
// expected output: ["first" => 2, "second" => 5, "third" => 8]


// Use value in internal array as value,
// Use "any" in internal array as key of array
$arrayUtils->column(null, "any");
// expected output: [
//   "first"  => ["any" => "first",  1, 2, 3],
//   "second" => ["any" => "second", 4, 5, 6],
//   "third"  => ["any" => "third",  7, 8, 9]
//]
```

{% endcode %}

## Syntax

```php
$arrayUtils->column(mixed $valueKey, mixed $indexKey = null) : ArrayUtils;
```

### Parameter

* `$valueKey`

  > The key value of the element to be used as the value.
  >
  > If is null, Use element to value.<br>
* `$indexKey` <img src="/files/-MKk9YjCz_YkVR1YiRy-" alt="" data-size="line">&#x20;

  > The key value of the element to be used as the key.\
  > Default is `NULL`. If is null, Re-index from 0.

### Return value

* A array of values representing a single column from the input array.

## Prefixing

```php
$arrayUtils->columnAs(mixed $valueKey, mixed $indexKey = null) : array;
```

```php
ArrayUtils::columnFrom(iterable $from, mixed $valueKey, mixed $indexKey = null) : ArrayUtils;
```

```php
ArrayUtils::(iterable $from, mixed $valueKey, mixed $indexKey = null) : array;
```

## References

{% embed url="<https://www.php.net/manual/en/function.array-column>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://arrayutils.docs.present.kim/methods/c/column.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
