Core Function IsKeySet
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> IsKeySet( <array>, <key> ) </pre> === Description === Check if given key exists within an array (hash/dictionary). === Parameters === ==== array ==== The array to use....") |
m (1 revision) |
||
(4 intermediate revisions by one user not shown) | |||
Line 25: | Line 25: | ||
=== Remarks === | === Remarks === | ||
− | + | Alias' for this command | |
+ | <pre> | ||
+ | IsIndexSet() | ||
+ | </pre> | ||
=== Example === | === Example === | ||
Line 43: | Line 46: | ||
println( "Key[Three] is : " . (IsKeySet($a, "Three") ? "SET" : "NOT SET") ); | println( "Key[Three] is : " . (IsKeySet($a, "Three") ? "SET" : "NOT SET") ); | ||
println( "Key[Four] is : " . (IsKeySet($a, "Four") ? "SET" : "NOT SET") ); | println( "Key[Four] is : " . (IsKeySet($a, "Four") ? "SET" : "NOT SET") ); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Alternative way using IsSet() | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | IsSet($a) # Check if $a is set | ||
+ | IsSet($a['Test']) # Check if $a (as array) index 'Test' is set | ||
+ | IsSet($a['Test']['Cat']) # Check if $a (as array) index 'Test' (as array) index 'Cat' is set | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:37, 14 June 2015
IsKeySet( <array>, <key> )
Contents |
Description
Check if given key exists within an array (hash/dictionary).
Parameters
array
The array to use.
key
The Key to check.
Return Value
Success - Returns 1.
Failure - Returns 0.
Remarks
Alias' for this command
IsIndexSet()
Example
$a = array("One" => "FoX", "Two" => "Cat", "Three" => "Dog"); println( "Key[One] is : " . (IsKeySet($a, "One") ? "SET" : "NOT SET") ); println( "Key[Two] is : " . (IsKeySet($a, "Two") ? "SET" : "NOT SET") ); println( "Key[Three] is : " . (IsKeySet($a, "Three") ? "SET" : "NOT SET") ); println( "Key[Four] is : " . (IsKeySet($a, "Four") ? "SET" : "NOT SET") ); // Delete a key and do it again unset($a["Two"]); println( "Key[One] is : " . (IsKeySet($a, "One") ? "SET" : "NOT SET") ); println( "Key[Two] is : " . (IsKeySet($a, "Two") ? "SET" : "NOT SET") ); println( "Key[Three] is : " . (IsKeySet($a, "Three") ? "SET" : "NOT SET") ); println( "Key[Four] is : " . (IsKeySet($a, "Four") ? "SET" : "NOT SET") );
Alternative way using IsSet()
IsSet($a) # Check if $a is set IsSet($a['Test']) # Check if $a (as array) index 'Test' is set IsSet($a['Test']['Cat']) # Check if $a (as array) index 'Test' (as array) index 'Cat' is set