Answer the question
In order to leave comments, you need to log in
How to get rid of the foreach loop and convert to array_map?
Good afternoon, dear experts, help me, how to get rid of the foreach construct in favor of array_map? Is it appropriate to get rid of it at all, and what to do with isset - there is an idea to take it into a separate function, where to transfer the resulting array. No experience in PHP, only Autoit and Pawn, don't kick too much)
function getData(array $arr){
$my = [];
$i=0;
foreach($arr['Value'] as $value){
$my[$i]['Турнир'] = $value['L'];
$my[$i]['Хозяева'] = $value['O1'];
$my[$i]['Хозяева счет'] = isset($value['SC']['FS']['S1'])?$value['SC']['FS']['S1']:0;
$my[$i]['Гости'] = $value['O2'];
$my[$i]['Гости счет'] = isset($value['SC']['FS']['S2'])?$value['SC']['FS']['S2']:0;
$my[$i]['Время матча']= isset($value['SC']['TS'])?intval(($value['SC']['TS']/60),0):"Скоро...";
$my[$i]['Тайм'] = $value['SC']['CPS'];
$i++;
};
print_r($my);
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question