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 in PHP by narikkadan
• 11,280 points
10 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,740 points
4,640 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,740 points
1,454 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,740 points
218 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,740 points
2,299 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,740 points
1,319 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,240 points
3,977 views
0 votes
0 answers

PHP multidimensional array search by value

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

May 30 in PHP by Kichu
• 19,040 points
13 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 in PHP by narikkadan
• 11,280 points
18 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 in PHP by Kithuzzz
• 3,660 points
19 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP