473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP array

rahulephp
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. )
Oct 13 '09 #1
1 1963
Dormilich
8,658 Expert Mod 8TB
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).
Oct 13 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.