/** * Get an array with the values of a given column. * * @param string $column * @param string $key * @return array */ public function lists($column, $key = null) { $columns = $this->getListSelect($column, $key); // First we will just get all of the column values for the record result set // then we can associate those values with the column if it was specified // otherwise we can just give these values back without a specific key. $results = new Collection($this->get($columns)); $values = $results->fetch($columns[0])->all(); // If a key was specified and we have results, we will go ahead and combine // the values with the keys of all of the records so that the values can // be accessed by the key of the rows instead of simply being numeric. if (!is_null($key) && count($results) > 0) { $keys = $results->fetch($key)->all(); return array_combine($keys, $values); } return $values; }
/** * Get an array with the values of a given column. * * @param string $column * @param string $key * @return array */ public function lists($column, $key = null) { $columns = $this->getListSelect($column, $key); // $results = new Collection($this->get($columns)); $values = $results->fetch($columns[0])->all(); if (!is_null($key) && count($results) > 0) { $keys = $results->fetch($key)->all(); return array_combine($keys, $values); } return $values; }