PHP | SplFixedArray offsetExists() Function
The SplFixedArray::offsetExists() function is an inbuilt function in PHP which is used to check provided index exist or not in an array.
Syntax:
bool SplFixedArray::offsetExists( $index )
Parameters: This function accepts single parameter $index which specifies the requested index.
Return Value: This function returns true if requested index found otherwise return false.
Below programs illustrate the SplFixedArray::offsetExists() function in PHP:
Program 1:
<?php // Create a fixed size array $gfg = new SplFixedArray(6); $gfg[0] = 1; $gfg[1] = 5; $gfg[2] = 10; // Check whether index exist or not var_dump($gfg->offsetExists(2)); ?> |
bool(true)
Program 2:
<?php // Create some fixed size array $gfg = new SplFixedArray(6); $gfg[0] = 1; $gfg[1] = 5; $gfg[2] = 1; $gfg[3] = 11; $gfg[4] = 15; $gfg[5] = 17; $i = 0; // Iterate array and print values while($i < 8) { // Check whether index exist or not var_dump($gfg->offsetExists($i)); $i++; } ?> |
bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(false) bool(false)
Reference: https://www.php.net/manual/en/splfixedarray.offsetexists.php
Recommended Posts:
- ArrayObject offsetExists() Function in PHP
- PHP | SplObjectStorage offsetExists() Function
- PHP | SplDoublyLinkedList offsetExists() Function
- PHP | SplFixedArray next() Function
- PHP | SplFixedArray key() Function
- PHP | SplFixedArray offsetGet() Function
- PHP | SplFixedArray count() Function
- PHP | SplFixedArray current() Function
- PHP | SplFixedArray __construct() Function
- PHP | SplFixedArray getSize() Function
- PHP | SplFixedArray setSize() Function
- PHP | SplFixedArray valid() Function
- PHP | SplFixedArray toArray() Function
- PHP | SplFixedArray rewind() Function
- PHP | SplFixedArray offsetUnset () Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




