Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8312125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:03:25+00:00 2026-06-08T20:03:25+00:00

I want to code a function to get parent’s children. get_children supposed to return

  • 0

I want to code a function to get parent’s children. get_children supposed to return an array of $this_parent_id children.

/* $pages array */

Array
(
    [0] => Pages Object
        (
            [id_page] => 1
            [str_title] => index
            [id_parent] => 0
        )

    [1] => Pages Object
        (
            [id_page] => 10
            [str_title] => download
            [id_parent] => 0
        )

    [2] => Pages Object
        (
            [id_page] => 11
            [str_title] => about us
            [id_parent] => 1
        )

    [3] => Pages Object
        (
            [id_page] => 12
            [str_title] => contact us
            [id_parent] => 1
        )

    [4] => Pages Object
        (
            [id_page] => 13
            [str_title] => members
            [id_parent] => 1
        )

)

I want to push child arrays into an array when condition is true.

print_r(get_children(1, $pages));
function get_children($this_parent_id, $family) {
    foreach($family as $page) {
        if ($page->id_parent == $this_parent_id) {
            /* here I need to append $page to $temp_array
        isset($temp_array) ? $temp_array = array($temp_array, (array)$page) : $temp_array = (array)$page; */
        }
    }
    return $temp_array;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:03:28+00:00Added an answer on June 8, 2026 at 8:03 pm
    print_r(get_children(1, $pages));
    function get_children($this_parent_id, $family)
    {
        global $temp_array;
        foreach ($family as $page) {
            if ($page->id_parent == $this_parent_id) {
                isset($temp_array) ? $temp_array[] = (array) $page : $temp_array = array((array) $page);
            }
        }
        return $temp_array;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to get the value of this td my code function check() {
I want to get script's origin filename in global functions. I tried following code,
I have a JavaScript function code where I want to alert. function msgalert(x,y) {
I have a JavaScript function code where I want to alert. function msg(x,y) {
I want to call my facebook send dialog function from code behind : The
In the following code I want to use the dilate function but I don't
I want the javascript code to be someFunction(42, function onSuccess() {}, function onFailure() {})
I have this piece of code in a function. I want to print the
I want to execute a javascript function in a c# code. Here is what
I want to use Container.ItemIndex in my Code Behind in my function in OnCustomColumnDisplayText

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.