Please tell me debager!

I recently started learning php, and I write in the atom editor (which my acquaintance advised me) - before that I set myself up and used sublime text (when I started learning html & css). Now I'm a little used to the atom editor. And in my past question, I was advised “first of all, when learning php, you need to figure out how to debug your scripts” @toxxxa. As I understand it, the debugger will show the execution of the code step by step! Tell me how to do this at atom.
And another question - why nothing is displayed?


<?php $datatxt=file("table.txt"); $lnarr=count($datatxt); for ($i=1; $i <= $lnarr; $i++) { $a=$lnarr[$i]; echo $a; } ?> 

table.txt

 name surname age 1 2 3 

PS: the idea of ​​the code is to make a table, and the fields, when filled in, go to the txt file, and then read and write to the table from there.

    1 answer 1

    You actually asked two questions. It is strange that they did not cover.

    As for the output from the file:

     <?php $datatxt=file("table.txt"); $lnarr=count($datatxt); for ($i=1; $i <= $lnarr; $i++) { $a=$lnarr[$i]; echo $a; } ?> 

    $ lnarr contains the number of elements in the array returned by the file function.

    One line - one element.

    You access $ lnarr as an array (although it is a number) and try to output the result instead of outputting data from $ datatxt

     <?php $datatxt=file("table.txt"); $lnarr=count($datatxt); for ($i=0; $i < $lnarr; $i++) { echo $datatxt[$i]; } ?> 

    The array indices are numbered from 0, in your case you set $ i = 1 thereby skipping the first element of the array. Ie start with the second.

    Because of the = sign in the loop, you will get an error, because at the end you will refer to a non-existent element of the array.

    As for debag:

    For atom'a there is a php-debug package using XDebug

    • Thank you!) But I still haven’t figured out about debugging (And how do I get the word on a line? Damn you're so cool)) I want a programmer’s friend)) - ALPHA
    • @ALPHA use explode . For example, $ str = "word word word"; $ arr = explode ("", $ str); The output will be an array and three ulementov. - UserName
    • Thanks, I was just thinking about such a function, I just didn’t know what it was called! ^^ - ALPHA