我有一个数组,其中包含一些不同点的数值。我想检查索引中是否有值,然后把它放在一个从0开始的新数组中,然后放入索引1,然后将下一个值放入索引2,依此类推。我需要缩短它并将它们全部移到左边。如何检查一个数组索引是否包含一个值
Array ([0] => 53 [1] => [2] => 55 [3] => 76 [4] => [5] => [6] => [7] =>)
新的阵列将是:
newArray ([0] => 53 [1] =>55 [2] => 76)
也许是这样的:
for ($i=0; $i < sizeof($questionWorth); $i++)
{
if($questionWorth[$i] has a value)
{
put it in new array starting at index zero
then increment the index of new array
}
}
你“也许是这样的”解决方案是好的另一个柜台。 – zerkms 2014-11-23 22:30:01
但我不没有如何在PHP中实现该解决方案... – 2014-11-23 22:30:39
'if($ questionWorth [$ i]!='')$ newArray [] = $ questionWorth [$ i];' – 2014-11-23 22:31:28