Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP array

Newbie
 
Join Date: Sep 2009
Posts: 14
#1: Oct 13 '09
I want to print array something like this

level1 level2

Who we are
. Welcome from jay(video)
. mission statement (Copy)
. vision(Copy)
. what we believe(copy)
. FAQ (copy)

Connect
. History
. Executive Profiles
. Resort Art
. Charities
. Blog

What's up
Staff
Contact
Give

[page_id] of level1 elements are same as [page_parent_id] of level
this is only field common between level1 & level2

My question is, what is the coding to print below array in above format?
(Using OOPS)

Array is here:
Debug:

Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [0] => Array
  4.         (
  5.             [page_id] => 18
  6.             [page_post_slug] => who-we-are.htm
  7.             [page_title] => Who we are
  8.             [page_level] => 1
  9.             [page_parent_id] => 2
  10.         )
  11.  
  12.     [1] => Array
  13.         (
  14.             [page_id] => 19
  15.             [page_post_slug] => connect.htm
  16.             [page_title] => Connect
  17.             [page_level] => 1
  18.             [page_parent_id] => 2
  19.         )
  20.  
  21.     [2] => Array
  22.         (
  23.             [page_id] => 21
  24.             [page_post_slug] => what-s-up.htm
  25.             [page_title] => What's up
  26.             [page_level] => 1
  27.             [page_parent_id] => 2
  28.         )
  29.  
  30.     [3] => Array
  31.         (
  32.             [page_id] => 22
  33.             [page_post_slug] => staff.htm
  34.             [page_title] => Staff
  35.             [page_level] => 1
  36.             [page_parent_id] => 2
  37.         )
  38.  
  39.     [4] => Array
  40.         (
  41.             [page_id] => 23
  42.             [page_post_slug] => contact.htm
  43.             [page_title] => Contact
  44.             [page_level] => 1
  45.             [page_parent_id] => 2
  46.         )
  47.  
  48.     [5] => Array
  49.         (
  50.             [page_id] => 24
  51.             [page_post_slug] => give.htm
  52.             [page_title] => Give
  53.             [page_level] => 1
  54.             [page_parent_id] => 2
  55.         )
  56.  
  57.     [6] => Array
  58.         (
  59.             [page_id] => 25
  60.             [page_post_slug] => welcome-from-jay-video-.htm
  61.             [page_title] => Welcome from jay(video)
  62.             [page_level] => 2
  63.             [page_parent_id] => 18
  64.         )
  65.  
  66.     [7] => Array
  67.         (
  68.             [page_id] => 26
  69.             [page_post_slug] => mission-statement--copy-.htm
  70.             [page_title] => mission statement (Copy)
  71.             [page_level] => 2
  72.             [page_parent_id] => 18
  73.         )
  74.  
  75.     [8] => Array
  76.         (
  77.             [page_id] => 27
  78.             [page_post_slug] => vision-copy-.htm
  79.             [page_title] => vision(Copy)
  80.             [page_level] => 2
  81.             [page_parent_id] => 18
  82.         )
  83.  
  84.     [9] => Array
  85.         (
  86.             [page_id] => 28
  87.             [page_post_slug] => what-we-believe-copy-.htm
  88.             [page_title] => what we believe(copy)
  89.             [page_level] => 2
  90.             [page_parent_id] => 18
  91.         )
  92.  
  93.     [10] => Array
  94.         (
  95.             [page_id] => 29
  96.             [page_post_slug] => faq--copy-.htm
  97.             [page_title] => FAQ (copy)
  98.             [page_level] => 2
  99.             [page_parent_id] => 18
  100.         )
  101.  
  102.     [11] => Array
  103.         (
  104.             [page_id] => 30
  105.             [page_post_slug] => history.htm
  106.             [page_title] => History
  107.             [page_level] => 2
  108.             [page_parent_id] => 19
  109.         )
  110.  
  111.     [12] => Array
  112.         (
  113.             [page_id] => 31
  114.             [page_post_slug] => executive-profiles.htm
  115.             [page_title] => Executive Profiles
  116.             [page_level] => 2
  117.             [page_parent_id] => 19
  118.         )
  119.  
  120.     [13] => Array
  121.         (
  122.             [page_id] => 32
  123.             [page_post_slug] => resort-art.htm
  124.             [page_title] => Resort Art
  125.             [page_level] => 2
  126.             [page_parent_id] => 19
  127.         )
  128.  
  129.     [14] => Array
  130.         (
  131.             [page_id] => 33
  132.             [page_post_slug] => charities.htm
  133.             [page_title] => Charities
  134.             [page_level] => 2
  135.             [page_parent_id] => 19
  136.         )
  137.  
  138.     [15] => Array
  139.         (
  140.             [page_id] => 34
  141.             [page_post_slug] => blog.htm
  142.             [page_title] => Blog
  143.             [page_level] => 2
  144.             [page_parent_id] => 19
  145.         )
  146.  
  147. )

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,670
#2: Oct 13 '09

re: PHP array


It looks like the data are coming from a DB. I’d rather not use this array, if I could get a better one. ideally you have an array that already represents the structure (otherwise you have to do quite some looping to get the pages sorted).
Reply