PHP array mapping

0 votes

Is there a cleaner way than foreach to get an array of all "label" values?

$methods[0]['label'] = 'test';
$methods[0]['nr']    = 99;
$methods[1]['label'] = 'whatever';
$methods[1]['nr']    = 10;


foreach($methods as $method) {
    $methodsLabel[] = $method['label'];
}
Jul 22, 2022 in PHP by narikkadan
• 63,600 points
351 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

How foreach change original array values in php?

Hello @kartik, Do the following: foreach ($fields as $key ...READ MORE

answered Aug 14, 2020 in PHP by Niroj
• 82,840 points
8,729 views
–1 vote
1 answer
0 votes
1 answer

How to remove duplicate values from an array in PHP?

Hello @kartik, Use array_unique(): Example: $array = array(1, 2, 2, 3); $array ...READ MORE

answered Sep 15, 2020 in PHP by Niroj
• 82,840 points
2,737 views
0 votes
1 answer

How to delete element by value in array (not key) using php?

Hello @kartik, Using array_search() and unset, try the following: if (($key = ...READ MORE

answered Sep 16, 2020 in PHP by Niroj
• 82,840 points
2,056 views
0 votes
1 answer

How to remove a variable from a PHP session array?

Hello @kartik, Try: if (isset($_POST['remove'])) { ...READ MORE

answered Nov 8, 2020 in PHP by Niroj
• 82,840 points
4,839 views
0 votes
1 answer

How to load return array from a PHP file?

Hii @kartik, When an included file returns something, ...READ MORE

answered Nov 10, 2020 in PHP by Niroj
• 82,840 points
3,185 views
0 votes
1 answer

How to check if array is multidimensional or not?

Since the 'second dimension' could be just ...READ MORE

answered Nov 5, 2018 in Others by DataKing99
• 8,250 points
5,947 views
0 votes
0 answers

PHP multidimensional array search by value

I want to search for the uid ...READ MORE

May 30, 2022 in PHP by Kichu
• 19,040 points
1,074 views
0 votes
0 answers

How to sum all column values in multi-dimensional array?

How can I add all the columnar ...READ MORE

Jun 19, 2022 in PHP by narikkadan
• 63,600 points
1,446 views
0 votes
0 answers

How to sort an array of associative arrays by value of a given key in PHP?

Given this array: $inventory = array( ...READ MORE

Jul 24, 2022 in PHP by Kithuzzz
• 38,000 points
649 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP