KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a common pattern which Im sure there must be a built-in array function in PHP to handle but just can't see it. I have multiple arrays such as the following: $testArray = array ( 'subArray1' => array( 'key1' => "Sub array 1 value 1", 'key2' => "Sub array 1 value 1" ), 'subArray2' => array( 'key1' => "Sub array 2 value 1", 'key2' => "Sub array 2 value 2" ) ); I need to get the key1 values from each subArray, of which there can be any number. I always end up just looping over each array to get the required values, but I'm sure there must be an easier, more efficient way to handle this. I am currently using the following simple foreach to parse the arrays: $preparedSubs = array(); foreach($testArray as $subArray) { $preparedSubs[] = $subArray['key1']; } It's as short as I can make it, but as I said I'm sure there is a PHP construct that would handle this better.
Tags (comma-separated)
Save Edits
Cancel