Return the last 2 digits a number

后端 未结 6 990
Happy的楠姐
Happy的楠姐 2021-01-11 15:00

How can I get the last 2 digits of:

200912

to my object:

$year = $flightDates-&         


        
6条回答
  •  礼貌的吻别
    2021-01-11 15:12

    Example 1 : You can just strip the tags with strip_tags and use substr

    $number = '200912' ;
    $year = substr(strip_tags($number), 0,2);
    var_dump($year);
    

    Example 2 : You can also use simplexml_load_string with substr

    $number = '200912' ;
    $year = substr(simplexml_load_string($number),0,2);
    var_dump($year);
    

    Output

    string '20' (length=2)
    

提交回复
热议问题