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
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,6 +292,22 @@ $data1->getInt("0.author.idx"); // Returns null because the field doesn't exists
292
292
$data1->getInt("0.author.idx", 44); // Returns 44 because the field doesn't exists, and you set a default, in this case 44
293
293
```
294
294
295
+
### The `getIntStrict()` method
296
+
297
+
The `getIntStrict()` method retrieves the value of a specified field as a integer from a data block. If the field does not exist or is null, it returns a default value, which can be customized (0 by default).
298
+
Parameters:
299
+
300
+
-`$path` (string): The path to the field (e.g., "0.author.id").
301
+
-`$default` (int): (Optional) The default value to return if the field doesn't exist. Defaults to 0.
302
+
-`$charNestedKey` (string): the character separator for nested field names. The default is ".".
303
+
304
+
Example usage:
305
+
```php
306
+
$data1->getIntStrict("0.author.id"); // Returns the field value as an integer, for example 678434
307
+
$data1->getIntStrict("0.author.idx"); // Returns 0 because the field doesn't exists, and the method is strict
308
+
$data1->getIntStrict("0.author.idx", 44); // Returns 44 because the field doesn't exists, and you set a default, in this case 44
309
+
```
310
+
295
311
### The `getBoolean()` method
296
312
297
313
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).
@@ -308,6 +324,22 @@ $data1->getBoolean("0.author.site_admin_notexists"); // Returns null because the
308
324
$data1->getBoolean("0.author.site_admin_notexists", true); // Returns true because the field doesn't exists, and you set a default, in this case true
309
325
```
310
326
327
+
### The `getBooleanStrict()` method
328
+
329
+
The `getBooleanStrict()` 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 strict boolean default value, which can be customized (false by default).
330
+
Parameters:
331
+
332
+
-`$path` (string): The path to the field (e.g., "0.author.id").
333
+
-`$default` (bool): (Optional) The default value to return if the field doesn't exist. Defaults to false.
334
+
-`$charNestedKey` (string): the character separator for nested field names. The default is ".".
335
+
336
+
Example usage:
337
+
```php
338
+
$data1->getBooleanStrict("0.author.site_admin"); // Returns the field value as an boolean, for example true
339
+
$data1->getBooleanStrict("0.author.site_admin_notexists"); // Returns false because the field doesn't exists
340
+
$data1->getBooleanStrict("0.author.site_admin_notexists", true); // Returns true because the field doesn't exists, and you set a default, in this case true
341
+
```
342
+
311
343
312
344
### The `getBlock()` method
313
345
If you need to manage a complex array (nested array) or an array obtained from a complex JSON structure, you can access a portion of the array and obtain the `Block` object via the `getBlock()` method.
0 commit comments