Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从链接数组中筛选出最高整数_Php_Arrays_Integer_Hyperlink - Fatal编程技术网

Php 从链接数组中筛选出最高整数

Php 从链接数组中筛选出最高整数,php,arrays,integer,hyperlink,Php,Arrays,Integer,Hyperlink,但这是一个令人困惑的标题,让我解释一下。我有一系列这样的链接: http://somesite.com/videoplayback?ip=81.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=905602&algorithm=throttle-factor&itag=34&ipbits=8&burst=40&sver=3&expire=128505

但这是一个令人困惑的标题,让我解释一下。我有一系列这样的链接:

http://somesite.com/videoplayback?ip=81.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=905602&algorithm=throttle-factor&itag=34&ipbits=8&burst=40&sver=3&expire=1285056000&key=yt1&signature=690F9475D5288F3129F84364427B2B490B6ACE59.45C8F83DEE3DD361855B12AE538EA6349FF8EF9B&factor=1.25&id=d50e6528eb51ad54,18

http://somesite.com/videoplayback?ip=81.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=905602&algorithm=throttle-factor&itag=18&ipbits=8&burst=40&sver=3&expire=1285056000&key=yt1&signature=A68EAA3F7A2ECA2BB2BD6C35BF443C03E4BB1172.AD2FF9FDAF046B23F789FE1A7F7882DF9A355DE4&factor=1.25&id=d50e6528eb51ad54,5

http://somesite.com/videoplayback?ip=81.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=905602&algorithm=throttle-factor&itag=5&ipbits=8&burst=40&sver=3&expire=1285056000&key=yt1&signature=ABC8ACF6899C46CC992ECB5F6A6FD7E66383EA3D.0C8B707083203DC1153FB26586A94BFAC64D176B&factor=1.25&id=d50e6528eb51ad54
如果你看一下这些URL的最末端,它们有扩展名,如
、18
、5
,还有最后一个链接根本没有这样的扩展名

现在,我需要在以后的代码中尽可能使用末端数字最高的链接。在本例中,我需要过滤掉第一个链接,因为它的末尾有最高的整数(
18

我会使用一系列
if()
块,但在这种情况下,末尾的整数可能会改变,因此这不是一个好的解决方案

所以我基本上需要遍历我的数组,检查哪个链接的末尾有最高的整数(注意它的长度只有两位数),然后将它存储在另一个变量中

有人能提供一些关于如何有效地做到这一点的示例/psudo代码吗


干杯。

即使URL中的其他位置有逗号,这也会起作用:

$links = array("http://somesite.com/videoplayback?ip=81.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=905602&algorithm=throttle-factor&itag=34&ipbits=8&burst=40&sver=3&expire=1285056000&key=yt1&signature=690F9475D5288F3129F84364427B2B490B6ACE59.45C8F83DEE3DD361855B12AE538EA6349FF8EF9B&factor=1.25&id=d50e6528eb51ad54,18", "http://somesite.com/videoplayback?ip=81.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=905602&algorithm=throttle-factor&itag=18&ipbits=8&burst=40&sver=3&expire=1285056000&key=yt1&signature=A68EAA3F7A2ECA2BB2BD6C35BF443C03E4BB1172.AD2FF9FDAF046B23F789FE1A7F7882DF9A355DE4&factor=1.25&id=d50e6528eb51ad54,5", "http://somesite.com/videoplayback?ip=81.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=905602&algorithm=throttle-factor&itag=5&ipbits=8&burst=40&sver=3&expire=1285056000&key=yt1&signature=ABC8ACF6899C46CC992ECB5F6A6FD7E66383EA3D.0C8B707083203DC1153FB26586A94BFAC64D176B&factor=1.25&id=d50e6528eb51ad54");

$max = 0;
$highestLink = "";
foreach ($links as $link) {
    $data = explode(",", strrev($link));
    $val = strrev($data[0]);
    if (is_numeric($val)) {
        $val = (int) $val;
        if ($val > $max) {
            $max = $val;
            $highestLink = $link;
        }
    }
}

echo $max;

即使URL中的其他位置有逗号,这也会起作用:

$links = array("http://somesite.com/videoplayback?ip=81.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=905602&algorithm=throttle-factor&itag=34&ipbits=8&burst=40&sver=3&expire=1285056000&key=yt1&signature=690F9475D5288F3129F84364427B2B490B6ACE59.45C8F83DEE3DD361855B12AE538EA6349FF8EF9B&factor=1.25&id=d50e6528eb51ad54,18", "http://somesite.com/videoplayback?ip=81.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=905602&algorithm=throttle-factor&itag=18&ipbits=8&burst=40&sver=3&expire=1285056000&key=yt1&signature=A68EAA3F7A2ECA2BB2BD6C35BF443C03E4BB1172.AD2FF9FDAF046B23F789FE1A7F7882DF9A355DE4&factor=1.25&id=d50e6528eb51ad54,5", "http://somesite.com/videoplayback?ip=81.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor&fexp=905602&algorithm=throttle-factor&itag=5&ipbits=8&burst=40&sver=3&expire=1285056000&key=yt1&signature=ABC8ACF6899C46CC992ECB5F6A6FD7E66383EA3D.0C8B707083203DC1153FB26586A94BFAC64D176B&factor=1.25&id=d50e6528eb51ad54");

$max = 0;
$highestLink = "";
foreach ($links as $link) {
    $data = explode(",", strrev($link));
    $val = strrev($data[0]);
    if (is_numeric($val)) {
        $val = (int) $val;
        if ($val > $max) {
            $max = $val;
            $highestLink = $link;
        }
    }
}

echo $max;

对于混淆奖:

array_multisort(
    array_map('intval',preg_replace('/^.*?(,([0-9]+))?$/','$2',$array)),
    $array);
echo end($array);

对于混淆奖:

array_multisort(
    array_map('intval',preg_replace('/^.*?(,([0-9]+))?$/','$2',$array)),
    $array);
echo end($array);

该死,如果不是因为“什么都没有”,我们可以使用一个u berevil
max(array_-map('intval',array_-map('strrev',array_-map('intval',array_-map('strev',$array')))哈哈,那是一条地狱般的线…该死,如果不是因为“什么都没有”,我们可以使用anüberevil
max(array_-map('intval',array_-map('strrev',array_-map('intval',array_-map('strev','strev',$array')))哈哈,那是一条该死的线…它没有在
$highestLink
中放任何东西,我马上会看一遍:)谢谢。PS:<代码>是什么意思if()
语句中的code>是什么意思?如果它不是
,它不是多余的吗?谢谢。它通过以下几行完成:
if($val>$max){…$highestLink=$link;
虽然我更改了代码(请参阅编辑),但我使用的
!!
不正确。我的意思是说
strstr(“,”,$line)===false
相反。你不能只使用
=
,因为如果
被发现在位置0,
0==false
,那么条件将被错误触发。
==
确保值是
false
而不是
0
。这不会在
$highestLink
中放入任何内容,我将在se中查看它c:)谢谢。PS:if()
语句中的
!!
是什么意思?if
不是多余的吗?谢谢。它是通过以下几行来实现的:
if($val>$max){…$highestLink=$link;
虽然我更改了我的代码(请参阅编辑),但我使用的
!!
不正确。我的意思是说
strstr,$line)===false
。您不能只使用
=
,因为如果
位于位置0,
0==false
,则条件将被错误触发。
==
确保值为
false
而不是
0
。是的,但多排序是通过引用实现的,因此
max(布尔真)
=>
true
将失败。OP不想要
max
,他想要“具有特定条件的url max”是的,但多排序是通过引用的,因此
max(布尔值true)
=>
true
将失败。OP不想要
max
,他想要“具有特定条件的url max”