PHP: TXT for Multilevel Array

Asked

Viewed 87 times

0

Guys, yesterday I had asked for help on the subject here that, promptly friends helped me, but I faced another problem:

Only later I realized that the file . TXT has several levels, and not just 2 as I had observed yesterday. I tried in all ways some strategy to solve the issue but it’s complicated for me. Next:

|0000|nome da empresa|cnpj|
|0100|nome do cliente|cod|
|0150|produto 1|preço|
|0150|produto 2|preço|
|0150|produto 3|preço|
|0100|nome do cliente|cod|
|0150|produto 1|preço|
|0150|produto 2|preço|
|0150|produto 3|preço| 
  1. |0000| is the company’s registration and encompasses everything, is unique in each TXT and is always UNIQUE in the first line.
  2. |0100| is the customer record, which is within the enterprise array (in 0000).
  3. |0150| are products purchased by that customer, within the customer array.

In this case, the expected result is the array below:

Array(
[0] => 0000, 
[1] => nome da empresa, 
[2] => cnpj, 
     [3] => array(
          [0] => 0100,
          [2] => nome do cliente, 
          [3] => cod, 
          [4] => array(
                     [0] => 0150, 
                     [1] => produto 1, 
                     [2] => preço,
                 )
          [5] => array(
                     [0] => 0150,
                     [1] => produto 2,
                     [2] => preço,
                 )
                 ...
      )
      ...
)

I am sorry to be repeating the question, I could not at all edit my previous question, besides finding that the other also has a very useful answer to the format presented there. I hope that there is a possibility of keeping this structure in a loop where there are several customers and products within the same company. Thank you in advance!

  • Lost access to another account?

  • IS 0100 or 100? Is it 0150 or 150? Your example is hard to understand.

  • Another question, there’s only one 0000 for each . txt?

  • I wasn’t able to activate the account, every time I logged in I gave the same thing (complete your registration) and I tried to guess how to do it. I cleaned the browser cache and then it worked. Well, it’s 0100, I typed "100" by mistake, I was pretty tired. Each txt has a single 0000 and is ALWAYS the first line. In the TXT example of yesterday that I was sent was not complete, which resulted in confusion.

  • I edited the question to make it easier to understand both who answers, and other possible users with the same question. ;)

  • @Guillhermenascimento

  • I’ve been very busy, tomorrow I give you an attention

  • All right, make yourself at home :)

  • How often will 0100 appear in this file? ?

  • He always shows up

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.