How to choose an array of array?

Good time of day. Tell me how to select specific arrays from the array:

Array
(
[0] => Array
(
[0] => 10+
[1] => 10*
[2] => 2+
)

[num] => Array
(
[0] => 10
[1] => 10
[2] => 2
)

[1] => Array
(
[0] => 10
[1] => 10
[2] => 2
)

[oper] => Array
(
[0] => +
[1] => *
[2] => +
)

[2] => Array
(
[0] => +
[1] => *
[2] => +
)

)

I need to choose the array with key "num" and "oper". And to bring the values of both arrays in a separate. Tell me in what ways it can be done, thanks in advance!
July 8th 19 at 12:08
2 answers
July 8th 19 at 12:10
Solution
$arrays = []; // here is your array of arrays
$needles = ['num', 'oper'];
$output = [];
foreach($arrays as $key => $array) {
 if(in_array($key, $needles) {
 $output = array_merge($output, $array);
}
}
All of this is here get data with array key [0] - Lindsay.Goldne commented on July 8th 19 at 12:13
Changed a bit the regex, and it worked! Thank you very much) - Lindsay.Goldne commented on July 8th 19 at 12:16
July 8th 19 at 12:12
Solution
$arr=array();
$all= your the array;
If (coun(array['num']>=coun(array['oper']){
$qty=coun(array['num'];}else{
$qty= coun(array['oper'])}
For ($i=0; $i <=$qty; $i++){
$arr[]=$all['num'][$i];
$arr[]=$all['oper'][$i];
}
$new_array = array_diff($arr, array("));
Thank you very much this helped) - Lindsay.Goldne commented on July 8th 19 at 12:15
Happy to try ) this solution will only work when the arrays are the same size that would rid it of zero values is a function $new_array = array_diff($old_array, array(")); and the loop do the array which is large Sammy count(max, array) - Lindsay.Goldne commented on July 8th 19 at 12:18
There was a small problem) I celebrate it not noticed. Your code captures only the number of 10,10,2 and another 10 it does not throw( - Lindsay.Goldne commented on July 8th 19 at 12:21
It was designed for 3 element . You provide the data for them I decided . 4 element out of the question )) may be altered to check - Pinkie_Rogah commented on July 8th 19 at 12:24
Yeah, now I changed the regular expression, and I now have 4 values. Now I will try) - Lindsay.Goldne commented on July 8th 19 at 12:27
All bomb)) Thank you) Got it right) - Pinkie_Rogah commented on July 8th 19 at 12:30
Mark this ) and I'm writing from the phone )) - Lindsay.Goldne commented on July 8th 19 at 12:33
Well, that's fine and I'm on the road is time killed ) - Lindsay.Goldne commented on July 8th 19 at 12:36
All there is now we have to solve the other problems) - Pinkie_Rogah commented on July 8th 19 at 12:39

Find more questions by tags PHP