Lasso Soft Inc. > Home

[ array->findposition ]

Method

The [array->findposition] method searches the array for the parameter and returns an array of positions for those elements which match. Accepts a single parameter of any data type including matchers. Optionally accepts a integer which is the offset position to begin searching the array at.

If the array contains any pair values, only the first part of the pair is compared with the parameter of the [array->findposition] method.

If no elements in the array match the parameter to the [array->findposition] method, or the offset parameter is outside of the size of the array, then an empty array is returned.

  • Syntax
array->findposition('search_term')

array->findposition('search_term', offset)
Examples
  • Beginner

Find the positions of the element in an array

Example 1:

Return the positions that 'John Doe' occurs at in an array of names

Code

var( myNames = array('John Doe', 'Jane Doe', 'Wendy Buck', 'John Doe', 'Jim Stag') )

$myNames->findposition('John Doe')

Result

array(1, 4)

Example 2:

Return the positions that John Doe occurs at in the array of name:position pairs after the first one.

Code

var( myNames = array('John Doe' = 'President', 
                     'Jane Doe' = 'Vice President', 
                     'Wendy Buck' = 'Treasurer', 
                     'John Doe' = 'Sales Manager', 
                     'Jim Stag' = 'Accountant') )

$myNames->findposition('John Doe', 2)

Result

array(4)

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2014 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft