我的产品阵列 -
Array
(
[0] => Product1
[1] =>
[2] =>
[3] =>
[4] => Product2
[5] =>
[6] =>
[7] => Product3
[8] => Product4
[9] => Product5
)
Desired output
-
Array
(
[0] => Product1
[1] => Product1
[2] => Product1
[3] => Product1
[4] => Product2
[5] => Product2
[6] => Product2
[7] => Product3
[8] => Product4
[9] => Product5
)
我的代码尝试 -
$i = 0;
$newone = array();
for( $i; $i < count($newarr); $i++ )
{
if( $newarr[$i] != '' )
{
$newone[$i] = $newarr[$i];
}
else
{
$newone[$i] = $newarr[$i-1];
}
}
echo "<pre>";print_r($newone);
此代码的输出 -
Array
(
[0] => Product1
[1] => Product1
[2] =>
[3] =>
[4] => Product2
[5] => Product2
[6] =>
[7] => Product3
[8] => Product4
[9] => Product5
)
让我知道如何操纵我的代码来实现这种数组。