【问题标题】:PHP get first numberPHP获取第一个数字
【发布时间】:2019-05-18 19:06:27
【问题描述】:

如何从函数中获取第一个数字?我需要检查一下有多少个数字?

$numbers = "1, 2, 3";

所以我的输出需要像1 is the first number, 3 numbers

【问题讨论】:

标签: php


【解决方案1】:

您可以尝试下一个示例。使用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

【讨论】:

    【解决方案2】:

    如果你使用数组而不是字符串会容易得多:

    $numbers = array (8, 32, 83);
    echo $numbers[0]." is first number, ";
    echo count($numbers)." numbers";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 2011-07-31
      • 1970-01-01
      • 2017-07-20
      • 1970-01-01
      • 2015-03-27
      相关资源
      最近更新 更多