How to Merge inner array elements in php using array functions?

Solution:1

Try this..this is your old array..try to arrange it..consider it as example..

 $array = array(0 => array("serial_id"=>"214"),  
              1 => array("serial_id"=>"218"), 
              2 => array("serial_id"=>"221"),
              3 => array("serial_id"=>"319")
              ); 

You can use foreach to get inner element in one new array $new_array = array(); foreach($array as $key=>$inner_array){

   foreach($inner_array as $k=>$v){
    $new_array[$k] = $v;
   }
}



  Output will be
$new_array = array(
    'serial_id_1' => string '214',
    'serial_id_2' => string '218',
    'serial_id_3' => string '221',
    'serial_id_4' => string '319',
);

Solution:2

You can try this code, I see that you are update your question

      <?php
    function convert_array($a) {
        for($j = 0; $j < count($a); $j++) {
            $b[$j] = $a[$j]['serial_id'];
        }
    return $b;
    }

   $array = array( array('serial_id' => 214),
         array('serial_id' => 218 ),
         array('serial_id' => 221),
         array('serial_id' => 319) );

    $array2 = convert_array($array);

        var_dump($array2);

        ?>  

If you use php > 5.5.0

   <?php

   $array = array( array('serial_id' => 214),
         array('serial_id' => 218 ),
         array('serial_id' => 221),
         array('serial_id' => 319) );

$array2 = array_column($array, 'serial_id');

    var_dump($array2);

    ?>