Hello,
I need some help with array manipulation. Actually I have an array with 24 entries as of 24 hours and I need to convert it to an array with 24*30 entries with the original values at every 30th place like
oldarray[0] = newarray[0]
oldarray[1] = newarray[30]
oldarray[2] = newarray[60]
and the values between the two indexes is filled by some computations on the original values . Then I need to merge two such arrays. The code I used is
// Observed data for 1
$t = array(30.0,28.9,31.1,30.0,28.3,26.7,26.1,31.7,33.3,32.8,33.9,36.7,37.8,38.9,40.0,41.1,41.1,41.1,40.6 ,39.4,36.7,34.4,33.3,31.1,28.9);
// Calculations for 1
$tatm1 = array();
for($i=0;$i<=24;$i++)
{
$tatm1[$intervals$i] =$t[$i];
}
for($i=0;$i<=24$intervals;$i++)
{
if($i%30==0)
{
$v=$tatm1[$i];
$m=$tatm1[$i+30];
}
else
{
$tatm1[$i]=($i%$intervals)*($m-$v)/$intervals+$v+273;
}
}
// Observed data for 2
$t = array(28.9,30.6,31.1,28.3,26.1,26.7,26.7,30.6,34.4,33.3,36.7,38.9,40.0,41.1,42.8,42.2,41.7,42.2,41.1 ,40.0,37.2,35.0,34.4,33.9,32.8);
// Calculations for 2
$tatm2 = array();
for($i=0;$i<=24;$i++)
{
$tatm2[$intervals$i] =$t[$i];
}
for($i=0;$i<=24$intervals;$i++)
{
if($i%30==0)
{
$v=$tatm2[$i];
$m=$tatm2[$i+30];
}
else
{
$tatm2[$i]=($i%$intervals)*($m-$v)/$intervals+$v+273;
}
}
$tatm=array_merge($tatm1,$tatm2);
print_r($tatm);
The code first fills the array[x*30] values and then the rest of the array.I thought while merging it will consider the values as per the index but it takes the first 24 entries which are placed at regular intervals of 30 as array[1-24] and then the rest values array[25-..] .
Why does it behave that way and doesnot merge according to the index? Is there any problem with the array_merge function?
I will try changing the code to fill the values altogether instead in two parts but all suggestions would be highly appreciated.
Thanks a tonn for the patience 🙂