Leave a Reply

1 comment

  1. // Correct way to convert string to integer 
    $begin = '34';
    $number = (int)$begin;
    var_dump( $number );
    int 34
    
    //Another correct way to convert string to integer
    $number = (int)get_post_meta( get_the_ID(), 'begin', true );
    var_dump( $number );
    int 34
    
    //strops() = Find the numeric position of the first occurrence of needle in the haystack string.
    // returns the numeric position or false if not found
    $var = strpos( $begin, ' ');
    var_dump( $var );
    boolean false
    
    //substr() = Returns the portion of string specified by the start and length parameters.
    //Your passing 0 as start and since false gets interpreted as 0 your passing 0 as length
    $substring = substr( $begin, 0, false );
    var_dump( $substring );
    string ' '
    
    //Same thing here but your converting the returned empty string into an integer which returns 0
    $substring = (int)substr( $begin, 0, false );
    var_dump( $substring );
    int  0