Core Function InArray

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> InArray( <array>, <needle>, <strict>, <flag> ) </pre> === Description === Checks if a value exists in an array === Parameters === ==== array ==== The array to use. ==...")
 
(Example)
Line 54: Line 54:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
 +
$os = array("Mac", "NT", "Irix", "Linux", 10, array("One", "Two", "Three"));
 +
if (inArray($os, "Irix"))
 +
    echo "Got Irix\n";
 +
else
 +
    echo "Not Got Irix\n";
 +
 +
if (inArray($os, "mac"))
 +
    echo "Got mac\n";
 +
else
 +
    echo "Not Got mac\n";
 +
 +
if (inArray($os, "mac", 0, 1))
 +
    echo "(ignoreCase) Got mac\n";
 +
else
 +
    echo "(ignoreCase) Not Got mac\n";
 +
 +
if (inArray($os, "10"))
 +
    echo "Got 10\n";
 +
else
 +
    echo "Not Got 10\n";
 +
 +
if (inArray($os, "10", 1))
 +
    echo "(strict) Got 10\n";
 +
else
 +
    echo "(strict) Not Got 10\n";
 +
 +
if (inArray($os, "Two"))
 +
    echo "(noRecursion) Got Two\n";
 +
else
 +
    echo "(noRecursion) Not Got Two\n";
 +
 +
if (inArray($os, "Two", 0, 2))
 +
    echo "(Recursion) Got Two\n";
 +
else
 +
    echo "(Recursion) Not Got Two\n";
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 13:10, 29 January 2013

InArray( <array>, <needle>, <strict>, <flag> )

Contents

Description

Checks if a value exists in an array

Parameters

array

The array to use.

needle

The searched value.

Note:

If needle is a string, the comparison is done in a case-sensitive manner.

(Unless the flag is set to ignore case)

strict

Optional; If true the the array value and the needle must be same TYPE such as both Int32s.

flag

Optional; Change how the InArray works

1 = Ignore case on string checks

2 = Use recursion

You can add them together for example:

1 | 2

Default: 0

Return Value

Success: Returns 1.

Failure: Returns -1.

Remarks

None.

Example

$os = array("Mac", "NT", "Irix", "Linux", 10, array("One", "Two", "Three"));
if (inArray($os, "Irix"))
    echo "Got Irix\n";
else
    echo "Not Got Irix\n";
 
if (inArray($os, "mac"))
    echo "Got mac\n";
else
    echo "Not Got mac\n";
 
if (inArray($os, "mac", 0, 1))
    echo "(ignoreCase) Got mac\n";
else
    echo "(ignoreCase) Not Got mac\n";
 
if (inArray($os, "10"))
    echo "Got 10\n";
else
    echo "Not Got 10\n";
 
if (inArray($os, "10", 1))
    echo "(strict) Got 10\n";
else
    echo "(strict) Not Got 10\n";
 
if (inArray($os, "Two"))
    echo "(noRecursion) Got Two\n";
else
    echo "(noRecursion) Not Got Two\n";
 
if (inArray($os, "Two", 0, 2))
    echo "(Recursion) Got Two\n";
else
    echo "(Recursion) Not Got Two\n";
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox