API16

API16:JArrayHelper/getColumn

From Joomla! Documentation

Revision as of 22:55, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Extracts a column from an array of arrays or objects <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JArrayHelper/getColumn|Edit De...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Extracts a column from an array of arrays or objects

[Edit Descripton]

Template:Description:JArrayHelper/getColumn

Syntax

getColumn(&$array, $index)
Parameter Name Default Value Description
$array The source array
$index $index The index of the column or name of object property

Returns

array Column of values from the source array

Defined in

libraries/joomla/utilities/arrayhelper.php

Importing

jimport( 'joomla.utilities.arrayhelper' );

Source Body

function getColumn(&$array, $index)
{
        $result = array ();

        if (is_array($array))
        {
                $n = count($array);
                for ($i = 0; $i < $n; $i++)
                {
                        $item = & $array[$i];
                        if (is_array($item) && isset ($item[$index])) {
                                $result[] = $item[$index];
                        } elseif (is_object($item) && isset ($item-> $index)) {
                                $result[] = $item-> $index;
                        }
                        // else ignore the entry
                }
        }
        return $result;
}

[Edit See Also] Template:SeeAlso:JArrayHelper/getColumn

Examples

<CodeExamplesForm />