You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -326,6 +326,42 @@ $data1->getIntStrict("0.author.idx"); // Returns 0 because the field doesn't exi
326
326
$data1->getIntStrict("0.author.idx", 44); // Returns 44 because the field doesn't exists, and you set a default, in this case 44
327
327
```
328
328
329
+
### The `getFloat()` method
330
+
331
+
The `getFloat()` method retrieves the value of a specified field as a float from a data block. If the field does not exist or is null, it returns a default value, which can be customized (`null` by default).
332
+
333
+
**Parameters:**
334
+
335
+
-`$path` (string): The path to the field (e.g., `"0.author.score"`).
336
+
-`$default` (null|float): (Optional) The default value to return if the field doesn't exist. Defaults to null.
337
+
-`$charNestedKey` (string): The character separator for nested field names. The default is `"."`.
338
+
339
+
**Example usage:**
340
+
341
+
```php
342
+
$data1->getFloat("0.author.score"); // Returns the field value as a float, for example 4.75
343
+
$data1->getFloat("0.author.notexists"); // Returns null because the field doesn't exist
344
+
$data1->getFloat("0.author.notexists", 1.5); // Returns 1.5 because the field doesn't exist, and you set a default
345
+
```
346
+
347
+
### The `getFloatStrict()` method
348
+
349
+
The `getFloatStrict()` method retrieves the value of a specified field as a float from a data block. If the field does not exist or is null, it returns a default value, which can be customized (`0.0` by default).
350
+
351
+
**Parameters:**
352
+
353
+
-`$path` (string): The path to the field (e.g., `"0.author.score"`).
354
+
-`$default` (float): (Optional) The default value to return if the field doesn't exist. Defaults to `0.0`.
355
+
-`$charNestedKey` (string): The character separator for nested field names. The default is `"."`.
356
+
357
+
**Example usage:**
358
+
359
+
```php
360
+
$data1->getFloatStrict("0.author.score"); // Returns the field value as a float, for example 4.75
361
+
$data1->getFloatStrict("0.author.notexists"); // Returns 0.0 because the field doesn't exist, and the method is strict
362
+
$data1->getFloatStrict("0.author.notexists", 1.5); // Returns 1.5 because the field doesn't exist, and you set a default
363
+
```
364
+
329
365
### The `getBoolean()` method
330
366
331
367
The `getBoolean()` method retrieves the value of a specified field as a boolean from a data block. If the field does not exist or is null, it returns a default value, which can be customized (null by default).
0 commit comments