function do_get_array() {
$posts[] = array(
'name' => 'Page',
'icon' => 'fa fa-users',
'fields' => array(
array(
'field_name' => 'Publisher Logo',
'id' => 'pub_logo',
'type' => 'text',
),
),
);
$posts[] = array(
'name' => 'Slideshow',
'icon' => 'fa fa-users',
'fields' => array(
array(
'field_name' => 'Publisher Logo2',
'id' => 'pub_logob',
'type' => 'text',
),
),
);
return $posts;
}
getting arrays from above function.
$posts = do_get_array();
$return = array();
foreach ($posts as $post) {
$return['name'] = $post['name'];
$return['icon'] = $post['icon'];
}
print_r($return);
but it only returns second array. I want it to return all the arrays value with key that i provided. I am actually new to php that's why i think i have some confusion.
$return['name'] = .... Why do you need a new array?foreach ($posts as $post) { $return[] = ['name' => $post['name'], 'icon' => $post['icon']]; }$return[] = ['name' => $post['name'], 'icon' => $post['icon']];and$postsshould be declared somewhere as an (empty?) array...