what is this code mean : return '/' === substr( get_option( 'permalink_structure' ), -1, 1 );
I know " get_option( permalink_structure ) " mean.
I read a wordpres plugin and see this code please answer me what is this code mean :::
return '/' === substr( get_option( 'permalink_structure' ), -1, 1 );
When I print this code , the number 1 is printed , my permalink_structure is "/%postname%/"
CodePudding user response:
return '/' === substr( get_option( 'permalink_structure' ), -1, 1 )
let's break this code.
get_option( 'permalink_structure' )
hereget_optionis a function that takes a string as input and as a result, it gives us a value from thewp_optionstable by matching the option name which we passed as an argument.substr( get_option( 'permalink_structure' ), -1, 1 )
substris an extraction function for a string you can read about in detail on the documentation page. string, offset, length are 3 params for this function. In the example option value is a string,-1is offset and1is the length. so here we're telling the function, here is the string now goto to offset-1, which is the first char from the end, and then from that point extract the1character.'/' === substr( get_option( 'permalink_structure' ), -1, 1 )
here===is called strict comparison, which means data type and value both should be same. so from point no. 2 code, we're expecting/assubstroutput and then we're comparing it with===return '/' === substr( get_option( 'permalink_structure' ), -1, 1 )
here usingreturnwe're returning the result of the comparison which will be either true or false.
I print this code, the number 1 is printed, and my permalink_structure is "/%postname%/"
1 is being printed because you're getting true as the result and if you'll echo/print the boolean true it will get print as 1
