私の製品配列 -
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
)
この種の配列を実現するためにコードを操作する方法を教えてください。