php - How can I simplify this array?
Get the solution ↓↓↓Solution:
You can use array_map.
PHP 5.3 or higher:
$callback = function($value) {
return $value['tag_id'];
};
$result = array_map($callback, $array);
Below 5.3:
function collapseTagIds($value) {
return $value['tag_id'];
}
$result = array_map('collapseTagIds', $array);
Answer
Solution:
Well, you could do this:
$new_array = array();
foreach($array as $key => $value)
{
$new_array[$key] = $value['tag_id'];
}
print_r($new_array);
Answer
Solution:
In your case, you have just one index on$value
. If you don't want to specify the index name just do it:
$new_array = array();
foreach($array as $key => $value) {
$new_array[$key] = reset($value);
}
print_r($new_array);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: please make sure the php redis extension is installed and enabled.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.