0
I have the following code.
$array = array(1,2,3);
$arr1 = array(3, 4, 5);
$data = [];
for($i = 0; $i < count($array); $i++){
$data["ca"] = $array[$i];
for($k = 0; $k < count($arr1); $k++){
$data["ser"] = $arr1[$k];
}
}
print_r($data);
the idea is that it goes through the whole array, thing it is not doing and as it goes through it prints as follows:
Array ( [ca] => 1 [ser] => 3 )
Array ( [ca] => 2 [ser] => 4 )
Array ( [ca] => 3 [ser] => 5 )
Ever tried to put
['ca'][] = $array[$i]
; Because in that case he’s just replacing the value– adventistaam
@adventistaam yes, only then it duplicates the values of my array.
– William
It is because the second for is within the first. So every time he will repeat
– adventistaam
@adventistaam yes, but I put in a loop inside another loop just to be able to cross the values, because if I put one outside the other it gives me this result Array ( [ca] => 1, [ca] => 2, [to be] => 1, [to be] => 2 ).
– William
But the values will be the ones in the array. Unless you take the second one for
– adventistaam
@adventist opa is true only had taken out the second
for
and put everything into onefor
, vlw.– William
I hope it worked
– adventistaam
Possible duplicate of Mount two-dimensional PHP array
– Woss