API16

JArrayHelper/getColumn: Difference between revisions

From Joomla! Documentation

m removing red link to edit, no existant pages
m preparing for archive only
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
Extracts a column from an array of arrays or objects
Extracts a column from an array of arrays or objects


<span class="editsection" style="font-size:76%;">
 
<nowiki>[<! removed edit link to red link >]</nowiki>
</span>


<! removed transcluded page call, red link never existed >
<! removed transcluded page call, red link never existed >
Line 58: Line 56:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[<! removed edit link to red link >]</nowiki>
</span>
<! removed transcluded page call, red link never existed >
<! removed transcluded page call, red link never existed >


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=getColumn
  category=getColumn
  category=JArrayHelper
  category=JArrayHelper
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*

Latest revision as of 01:19, 25 March 2017

Description

Extracts a column from an array of arrays or objects


<! removed transcluded page call, red link never existed >

Syntax

getColumn(&$array, $index)
Parameter Name Default Value Description
&$array $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;
}


<! removed transcluded page call, red link never existed >

Examples

Code Examples