douhao7677
2018-04-02 22:03
浏览 67
已采纳

从php中的数组中获取对称整数的总数?

ok so i have array for example $arr= "/43sdsd555ksldk66sd"544fdfd";

I take numbers using preg_match_all '/\d+/', and array_map('intval', $zni[0]);

Now the problem is i need to reverse those whole int to see if they are symmetric,like 555 and 66 , and if they are GET A TOTAL OF THEM.(total of only symmetric numbers)

i tried to use function " strrev "and got symmetric numbers, but i don't know how to put them in a one place IF THEY ARE symmetric and calculate them.

<?php
$numbers = "";

if (isset($_GET['submit']))
{
    $numbers = ($_GET['niz']);
    preg_match_all('/\d+/', $numbers, $zni);
    $numtwo= array_map('intval', $zni[0]);
}

foreach ($numtwo as $num)
{
    $reverse = strrev($num);
    var_dump($reverse);

    if ($num == $reverse)
    {
        $reverse = "true";
    } else {
        $reverse = "false";
    }
    var_dump($reverse);
}

1条回答 默认 最新

相关推荐 更多相似问题