Given a multi-dimensional array, I’m looking for a method that will extract various parts of that array, given variable (i.e., different) criteria.
For example, if this is my data:
array(
'0' => array(
'0' => 'aaaaaa',
'1' => 'bbbbb',
'2' => 'ccccc'
),
'1' => array(
'0' => 'aa2ssa',
'1' => 'bb3242bb,
'2' => 'ccccc234'
),
'2' => array(
'0' => 'aaa234aa',
'1' => 'b3242b',
'2' => 'cewrcc'
),
(etc)
)
I want to be able to call a function
function new_array( index, sub_index )
that returns an array based upon the index and sub_index parameters. Using the same data but different parameters would return different data.
Example 1
new_array( array(0, 2), ( array(1, 2), array(0, 2) ) )
Expected results:
array(
'0' => array(
'1' => 'bbbbb',
'2' => 'ccccc'
),
'2' => array(
'0' => 'aaa234aa',
'2' => 'cewrcc'
)
)
Example 2
new_array( array(2), ( array(0, 2) ) )
Expected results:
array(
'2' => array(
'0' =>'aaa234aa',
'1' => 'b3242b'
)
)
Anybody know how to do this? Thank you!
An alternate solution to @Orbling’s is this:
Results in an array with random entries. The outcome of the above would be: