131

Built-In Functions
Index

  • The index() function returns the position (integer offset) of the first occurence of a substring

  • Returns -1 if the substring cannot be found

      $myString = "Hello World";
      $val = index( $myString, "llo" );
      # Yields 2

      $val = index( $myString, "x" );
      # Yields -1

  • You may also specify an offset from which to start the search

      $myString = "Hello World";
      $val = index( $myString, "o", 5 );
      # Yields 7