API15

Difference between revisions of "JArrayHelper/getColumn"

From Joomla! Documentation

< API15:JArrayHelper
(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...)
 
m (preparing for archive only)
 
(3 intermediate revisions by 2 users 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>[</nowiki>[[Description:JArrayHelper/getColumn|Edit Descripton]]<nowiki>]</nowiki>
 
</span>
 
  
{{Description:JArrayHelper/getColumn}}
+
 
 +
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 17: Line 15:
 
!Description
 
!Description
 
|-
 
|-
|  
+
| &$array
 
|  
 
|  
 
|  $array The source array  
 
|  $array The source array  
Line 58: Line 56:
 
</source>
 
</source>
  
<span class="editsection" style="font-size:76%;">
+
 
<nowiki>[</nowiki>[[SeeAlso:JArrayHelper/getColumn|Edit See Also]]<nowiki>]</nowiki>
+
<! removed transcluded page call, red link never existed >
</span>
 
{{SeeAlso:JArrayHelper/getColumn}}
 
  
 
===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=*
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API15]]

Latest revision as of 19:18, 24 March 2017

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Extracts a column from an array of arrays or objects


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

Syntax[edit]

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[edit]

array Column of values from the source array

Defined in[edit]

libraries/joomla/utilities/arrayhelper.php

Importing[edit]

jimport( 'joomla.utilities.arrayhelper' );

Source Body[edit]

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[edit]

Code Examples[edit]