S
S
Sergey Beloventsev2018-03-02 10:02:55
PHP
Sergey Beloventsev, 2018-03-02 10:02:55

Why is the array formed in this way?

I form the array in this way

$arrInsert[]=$innerArr;
foreach (listВiv as $div)
     {
          $innerArr=array();
          if (is_object($div->adress))
          {
               $innerArr['adress']=$adress->text;
          }
          if (is_object($div->codes))
          {
               foreach ($div->codes->children as $child){
                    $arrExpl=explode(': ', $child->text);
                    $coneNames=($arrExpl[0]=='ОГРН')?'ogrn':'inn';
                    $innerArr[$coneNames]=$arrExpl[1];
               }
          }
          $arrInsert[]=$innerArr;
     }
     var_dump($arrInsert);

wanted to get
3 => 
    array (size=3)
      'adress' => string 'Город, улица дом.квартира' (length=142)
      'ogrn' => string '1234567890' (length=13)
      'inn' => string '0987654321' (length=10)

but I get
3 => 
    array (size=1)
      'adress' => string 'Город, улица дом.квартира' (length=142)
5 => 
    array (size=2)
      'ogrn' => string '1234567890' (length=13)
      'inn' => string '0987654321' (length=10)

Why don't you tell me where I'm stupid and how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-03-02
@Minifets

Your adress and ogrn+inn data are in different divs.
First, an array is formed from the 1st div, and the array is pushed into the resulting array. Then an array is formed from the 2nd div, and pushed into the result as a separate array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question