123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|681|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Web Development -> PHP missing array grandchild

Fri, 23 Sep 2011, 05:37
HoboBen
I have some code for building a HTML table from PHP.



Usage:


And the result:


If you note, var_dump($tr) correctly dumps the <tr>, including child <td> elements.

However, var_dump($table), while correctly var_dumping the <tr> elements, does not var_dump the grandchild <td> elements -- note the empty array ["td"]=> array(0) { }

Do you know why this might be happening?

Thanks

-=-=-
blog | work | code | more code
Sat, 24 Sep 2011, 05:29
HoboBen
I got an excellent answer on StackOverflow, which explains the problem.

Sigh, why can't everything use C-style pointers? I hate it when PHP does "magic".

-=-=-
blog | work | code | more code
Sun, 25 Sep 2011, 04:19
JL235
What version of PHP are you using?

It's my understanding that PHP uses references instead of copying in recent versions (at least in 5.3).
Sun, 25 Sep 2011, 13:32
HoboBen
5.3.3 on my laptop (where I ran the code) slightly older on the server.



It was a great answer though: the ampersand in the function definition was something I didn't know how to do in PHP. It solved the immediate problem and also taught me how to apply this to other situations.

-=-=-
blog | work | code | more code