如何從函數(shù)中獲取第一個(gè)數(shù)字?我需要檢查有多少個(gè)數(shù)字?$numbers = "1, 2, 3";所以我的輸出需要像 1 is the first number, 3 numbers
2 回答

慕容708150
TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超4個(gè)贊
你可以試試下一個(gè)例子。使用explode()來分割文本:
<?php
$numbers = "1, 2, 3";
$array = explode(', ', $numbers);
echo $array[0]." is the first number, ".count($array)." numbers";
?>
輸出:
1 is the first number, 3 numbers

GCT1015
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊
如果使用數(shù)組而不是字符串會容易得多:
$numbers = array (8, 32, 83);
echo $numbers[0]." is first number, ";
echo count($numbers)." numbers";
- 2 回答
- 0 關(guān)注
- 413 瀏覽
添加回答
舉報(bào)
0/150
提交
取消