I know this is probably a very simple question but I have looked around and most answers relate to array intersections which is not what I am looking for.
Example:
I have an array ($rows). When running print_r($rows) I get:
Array (
[0] => Array (
[id] => 184
[0] => 184
[name] => Advantage Membership
[1] => Advantage Membership
[flag] => 4
[2] => 4
)
[1] => Array (
[id] => 238
[0] => 238
[programname] => Package 2
[1] => Package 2
[flag] => 5
[2] => 5
)
)
I want to essentially create a ‘sub’ array which contains all of the ‘flag’ fields in my $rows array so that I can THEN do a if(in_array()) statement with another value.
ideal result array would look like:
$array2 = array( '4', '5' )
Then I could run the following and be happy:
if (in_array(4, $array2)) ...
Any suggestions?
What’s wrong with a custom function?
Or, as others have suggested,
array_mapis a good alternative.demos of both methods