M
M
Meled2019-01-02 20:03:15
PHP
Meled, 2019-01-02 20:03:15

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);
};

Good mood to you all )

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2019-01-02
@Meled

there is no point in redoing it.

G
grinat, 2019-01-02
@grinat

It looks great, when you look at it, almost no blood flows from the eyes, and the names are very informative, it’s immediately clear what it is about - leave it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question