Reputation: 3289
I have the following 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
)
)
Would like to get the resultant array as below
Array
(
[0] => IT Software - Application Programming, Maintenance
[1] => IT Software - eCommerce, Internet Technologies
[2] => IT Software - Client/ Server Programming
[3] => IT Software - Other
)
can i get a simple one liner other than array_column()
because im running php version below 5.5. I tried $funcmerged = array_reduce($functionalres, 'array_merge', array());
but iam not getting desired result.
Upvotes: 0
Views: 74
Reputation: 3289
Found a pretty good solution
How to Flatten a Multidimensional Array?
function flatten(array $array) {
$return = array();
array_walk_recursive($array, function($a) use (&$return) { $return[] = $a; });
return $return;
}
Hope it helps.
Upvotes: 0
Reputation: 5444
Try this..
<?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);
?>
Result:
Array ( [0] => IT Software - Application Programming, Maintenance
[1] => IT Software - eCommerce, Internet Technologies
[2] => IT Software - Client/ Server Programming
[3] => IT Software - Other )
Upvotes: 0
Reputation: 3195
Your code should be
$newArr = array();
foreach($currentArr as $key=>$val){
$newArr[] = $val['title'];
}
print_r($newArr);
Upvotes: 1
Reputation: 31749
Try this -
$new = array();
foreach($yourArray as $value) {
$new[] = $value['title'];
}
var_dump($new);
Upvotes: 1