如何将数组的数组合并为一个 php

How to merge array of arrays into one php

我有以下数组。

 Array
    (
        [0] => Array
            (
                [title] => IT Software - Application Programming, Maintenance 
            )

        [1] => Array
            (
                [title] => IT Software - eCommerce, Internet Technologies 
            )

        [2] => Array
            (
                [title] => IT Software - Client/ Server Programming
            )

        [3] => Array
            (
                [title] => IT Software - Other 
            )

    )

想要得到如下结果数组

Array
(
    [0] => IT Software - Application Programming, Maintenance

    [1] => IT Software - eCommerce, Internet Technologies 

    [2] => IT Software - Client/ Server Programming

    [3] => IT Software - Other 


)

除了array_column(),我能得到一个简单的衬垫吗,因为我运行的是低于 5.5 的 php 版本。我尝试了 $funcmerged = array_reduce($functionalres, 'array_merge', array()); 但我没有得到想要的结果。

试试这个 -

$new = array();
foreach($yourArray as $value) {
    $new[] = $value['title'];
}
var_dump($new);

您的代码应该是

$newArr = array();
foreach($currentArr as $key=>$val){
    $newArr[] = $val['title'];
}
print_r($newArr);

试试这个..

<?php
$newarray=array();
$array=array
(
    "0" => array("title"=>"IT Software - Application Programming, Maintenance"),
    "1"     => array("title"=>"IT Software - eCommerce, Internet Technologies   "),
    "2"    => array("title"=>"IT Software - Client/ Server Programming"),
    "3"    => array("title"=>"IT Software - Other")
); 

         foreach($array as $key =>$arrayvalue)
         {
         $newarray[]=$arrayvalue['title'];
         }
print_r($newarray);
?>

结果:

    Array ( [0] => IT Software - Application Programming, Maintenance 
[1] => IT Software - eCommerce, Internet Technologies   
[2] => IT Software - Client/ Server Programming 
[3] => IT Software - Other )

找到了一个很好的解决方案

How to Flatten a Multidimensional Array?

function flatten(array $array) {
        $return = array();
        array_walk_recursive($array, function($a) use (&$return) { $return[] = $a; });
        return $return;
    }

希望对您有所帮助。