为什么array_search不能在这里工作?

时间:2015-11-04 01:16:21

标签: php

我正在编写一个进度条脚本,它对于前端是动态的,结果不起作用,但我已经接近完成了它。我相信对你们中的一些人来说这将是一项轻松的任务。请问这里有什么问题?

// Progress Bar configurations
$data = array(
    array('bronze_V','bronze_IV','bronze_III','bronze_II','bronze_I'),
        array('silver_V','silver_IV','silver_III','silver_II','silver_I'),
        array('gold_V','gold_IV','gold_III','gold_II','gold_I'),
        array('platinum_V','platinum_IV','platinum_III','platinum_II','platinum_I'),
        array('diamond_V','diamond_IV','diamond_III','diamond_II','diamond_I')
);
foreach ($data as $key => &$value):
    $value = implode(",", $value);
endforeach;
$dataimplode = explode(",",(implode(",", $data)));

$startKey = array_search($start_rank, $dataimplode);
$currentKey = array_search($current_rank, $dataimplode);
$endKey = array_search($finish_rank, $dataimplode);

$orderPercent = (($currentKey-$startKey)/($endKey-$startKey))*100;
echo "<pre>", var_dump($dataimplode), "</pre><br/>";
echo $startKey;
echo $currentKey;
echo $endKey;

1 个答案:

答案 0 :(得分:0)

看起来我设法解决了这个问题,似乎唯一的问题是与$ current_rank在DB中的所有Caps中有关,所以它无法匹配它。 $ start_rank似乎工作正常我相信即使它应该返回0。