Jump to content
Larry Ullman's Book Forums

Chapter 1 To-Do List, Recursive

Recommended Posts


About script 1.3 view_tasks.php

Question1: How can the code below see if the task has a subtask by looking at the task's task_id?

Question2: Is there a way to determine if the task's parent_id=0 inside the foreach? (I want to add a link to each Main task)

// Check for subtasks:
if (isset($tasks[$task_id])) {
// Call this function:

Link to comment
Share on other sites

  • 3 weeks later...

Larry hello!


I like your books very much! They are easy to read and understand.

I'm also very much impressed with some ideas in your code.

According with PHP5 Advanced book they are Parent_sort function together with usort and recursive Make_list functions.


How do you know that? How do you get inspired with such an ideas?

Books? Practice? Expirience?


Can you recommend something to read extra?


With best regards,


Link to comment
Share on other sites

Larry thanks for your qucik reply!


Unfortunately I can not say exactly what I'm looking for....

It's all about some nice and cute ideas, algorithms, solutions and code snippets.


For example:

now I'm working with product catalog (add-delete-update/rename items, unlimited levels, tree structure etc.) and a couple of solutions from your PHP5 Advanced book were perfect for it!

If I havn't read your book I'd probably use at list two tables with realtions and it would not be as easy as idea from your book: one table is enough together with sorting function and recursive function.

And something like this.


Or may be vice versa: if I use two tables (one for nodes/parents another table for children and relations in-between) may be it would be easier,better and more flexible?

What do you think?


Best Regards,


Link to comment
Share on other sites

Recursion is a very specific programming solution. In most cases regular loops will do the job perfectly, but in those special cases the power of recursion cannot be beaten. If you read up on recursive programming, you will see there's even rules for how to write recursive algorithms.


If you are interested in the more advanced asPects of programming, you should read up on big O-analysis, data structures and object-oriented programming. How does functions like mysql_fetch_array() works? Why is array_key_exsist a faster function than in_array in most cases?


Getting a better understandment for how basic functionally works if often a good idea. Could you write a custom function that is faster than in_array()? Could you implement the iterator used in mysql_fetch_array() in your own code for easy array iterations? These are possible next steps. ;)

Link to comment
Share on other sites

Hi Antonio!


Thank you for your post!

I will try to follow your ideas to deeply understand programming.


Can you please recommend some books (I have already 3 PHP books of Larry)?

What programming or algorithm book impressed you best of all?


Thank you!

Link to comment
Share on other sites

I don't really know what to suggest to you. Larry might have something to add.


I would recommend you to learn how to use objects, learn a little about algorithms, and to just play with PHP.


I tried a youtube-search, and

looks like a good introduction to algorithms. It is not written in PHP, but it applies to PHP as well. Do not focus to much on math here. What's important is to have a basic understanding of how fast algorithms are when finding/sorting etc. I haven't looked trough more than one video, but it looks promising.


This will give you an understanding on why you should use associative arrays in PHP (They are called hash maps in some other languages) and how to write fast code in general. This will give you a better understanding of how data is saved and manipulated inside a PHP array. (Read about PHP arrays in the manual) What's special with PHP arrays are that they can be used as Stacks, queues, hash maps, linked lists and general collections in. In many other languages, these are different data structures with different strengths and weaknesses. Understanding arrays are in other words VERY important in PHP.

Link to comment
Share on other sites


  • Create New...