简体   繁体   English

如何从数组或字符串中获取数字值?

[英]How to get number value from array or string?

I have a list on the page. 我在页面上有一个列表。 And I want to get only amount (to be more specific, only total sum). 我只想得到金额(更具体而言,只有总数)。 So I tryed ot do it via post an array which i transform and i get rows like: 所以我尝试通过发布一个我转换的数组来做它,并且得到如下行:

"recived from player"

"0.000058"

"2014-06-30 15:21:46 UTC"

I have tryied to get an if(is_numeric($row1)) but it doesn't work (blank page). 我试图获得一个if(is_numeric($row1))但它不起作用(空白页)。

    foreach ($p as $r) {
    $row = str_replace("\t",'<br />',$r);
            $row1 = str_replace("silver","",$row);
        if (is_numeric($row1)) {
            echo $row1;
        }
}

Any idea how to solve it? 知道如何解决吗?

It will be better to split string to array and then check for Number. 最好将字符串拆分为数组,然后检查Number。

      $wordChunks = explode(" ", $someWords);  

      for($i = 0; $i < count($wordChunks); $i++)
           {
                if (is_numeric($wordChunks[$i])) 
                      {
                        echo $wordChunks[$i];
                      }

           }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM