動態陣列上的元素明智 iif
函式。
和
array_iff()
函array_iif()
式相等
語法
array_iff(
condition_array、 when_true、 when_false)
深入瞭解 語法慣例。
參數
姓名 | 類型 | 必要 | 描述 |
---|---|---|---|
condition_array | dynamic |
✔️ | 布爾值或數值的陣列。 |
when_true | 動態或純量 | ✔️ | 值或基本值的陣列。 這是當condition_array為 true 時的結果。 |
when_false | 動態或純量 | ✔️ | 值或基本值的陣列。 當 condition_array 為 false 時,這是結果。 |
注意
- 傳回值的長度與輸入 condition_array相同。
- 如果不等於 0,則會考慮
true
數值條件值。 - 非數值和非布爾值條件值在傳回值的對應索引中為 null。
- 如果 when_true 或 when_false 比 condition_array短,則會將遺漏的值視為 null。
傳回
根據條件陣列的對應值,傳回取自 when_true 或 when_false 陣列值的動態數位。
範例
下列範例示範如何使用 函 array_iff()
式來評估數位中的元素。
print condition=dynamic([true,false,true]), if_true=dynamic([1,2,3]), if_false=dynamic([4,5,6])
| extend res= array_iff(condition, if_true, if_false)
輸出
條件 | if_true | if_false | res |
---|---|---|---|
[true、false、true] | [1, 2, 3] | [4, 5, 6] | [1, 5, 3] |
下列範例示範如何將數值條件值視為布爾值。
print condition=dynamic([1,0,50]), if_true="yes", if_false="no"
| extend res= array_iff(condition, if_true, if_false)
輸出
條件 | if_true | if_false | res |
---|---|---|---|
[1, 0, 50] | 是 | 否 | [是,否,是] |
下列範例示範如何使用 函 array_iff()
式搭配非數值和非布爾值。
print condition=dynamic(["some string value", datetime("01-01-2022"), null]), if_true=1, if_false=0
| extend res= array_iff(condition, if_true, if_false)
輸出
條件 | if_true | if_false | res |
---|---|---|---|
[true、false、true] | 1 | 0 | [null, null, null] |
下列範例示範函式如何處理不相符的陣列長度。
print condition=dynamic([true,true,true]), if_true=dynamic([1,2]), if_false=dynamic([3,4])
| extend res= array_iff(condition, if_true, if_false)
輸出
條件 | if_true | if_false | res |
---|---|---|---|
[true、true、true] | [1, 2] | [3, 4] | [1, 2, null] |