0

i have two arrays in php

  Array
     (
       [0]=>30
     )
  Array
     (
       [0]->43
     ) 

i want to merge these arrays in a single array my desired output is

  Array
      (
       [0]=>30
       [1]=>43
      )

can anyone tell me how to achieve this

      function get_minutes($sess_time)
    {
# code...
if (strstr($sess_time, ':'))
{
    $separatedData = split(':', $sess_time);

    $minutesInHours    = $separatedData[0] * 60;
    $minutesInDecimals = $separatedData[1];

    $totalMinutes = $minutesInHours + $minutesInDecimals;
}
else
{
    $totalMinutes = $sess_time * 60;
}
if ($totalMinutes<=60) 
{
    # code...
    return $totalMinutes;
}
else
{
$result=$totalMinutes/60;
$y=explode(".",$result);
$hours=$y[0];
$hours_mins=$hours*60;
$remaining_mins=$totalMinutes-$hours_mins;
$remaining_array=array($remaining_mins);
 print_r($remaining_array);
}

}

when i print the remaining array the ourput is two arrays

Masooma Ahmad
  • 63
  • 1
  • 1
  • 7

2 Answers2

0

Try to use array_merge function.

Boris Savic
  • 781
  • 5
  • 9
0

array_merge — Merge one or more arrays

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.

If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.

Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.

<?php
$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
print_r($result);
?>

Output:

Array

(
    [color] => green
    [0] => 2
    [1] => 4
    [2] => a
    [3] => b
    [shape] => trapezoid
    [4] => 4
) 

Reference: http://www.w3schools.com/php/func_array_merge.asp

Community
  • 1
  • 1
Naresh Kumar P
  • 4,127
  • 2
  • 16
  • 33