我有號碼14969126,想分開像獲取數字的一部分,不同的變量
$last_five_digits = 69126;
$rest_of_digits = 149;
我已經試過
$last_five_digits = substr($postalcode, -5);
但我怎麼能得到的數字休息。
請提供任何建議。
謝謝。
我有號碼14969126,想分開像獲取數字的一部分,不同的變量
$last_five_digits = 69126;
$rest_of_digits = 149;
我已經試過
$last_five_digits = substr($postalcode, -5);
但我怎麼能得到的數字休息。
請提供任何建議。
謝謝。
您可以使用:
$firstDigits = substr($postalcode, 0, -5);
//=> 149
preg_split()
返回數組:
list($first, $last_five) =
preg_split('/(\d{5})$/', '14969126', null, PREG_SPLIT_DELIM_CAPTURE);
$postalcode = 14969126;
$last_five_digits = substr($postalcode, -5);
$rest_of_digits = substr($postalcode,0,3);
儘管此代碼可能回答此問題,但爲何和/或如何使用此代碼來回答問題提供了其他上下文,這可以提高其長期價值。 – David
它的工作,再次感謝您。 – Adas