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

  • SEARCH
  • Home
  • 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 6730249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:23:12+00:00 2026-05-26T10:23:12+00:00

In following php code in here //print_r($reunits); is output this: http://pastebin.com/RbqZ5kHV but in here

  • 0

In following php code in here //print_r($reunits); is output this: http://pastebin.com/RbqZ5kHV

but in here echo json_encode($reunits); is output as: http://pastebin.com/GFdHkg5Y

If use $reunits = array('reunits'=>$units_data); as: $reunits .=... i get this output in echo json_encode($reunits);: “ArrayArrayArray”

How can put output like output in //print_r($reunits); on output echo json_encode($reunits);? How can fix it?

$reunits = "";
//$tourf_id   = $this->input->post('tour_name');
$tourf_id = '102';
//$query_r = $this->db->order_by('id','desc')->get_where('tour_foreign_residence', array('relation' => $tourf_id));
$query_r = array('77192276', '15190364', '15183965')
foreach($query_r->result() as $idx=>$val){
    $hotel_id = $val->hotel_id;
    $query = $this->db->get_where('tour_foreign_units', array('hotel_id' => $hotel_id));
        $units_data = array();
        foreach ($query->result() as $index=>$row) {
            $units_data[] = array(
                'name' => $row->name,
                'price' => $row->price,
                'extra' => $row->extra,
                'hotel_id' => $row->hotel_id
            );
        }
    $reunits =  array('reunits'=>$units_data);
    //print_r($reunits);
}
echo json_encode($reunits);

This output send by json_encode to ajax call in jquery.

  • 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-05-26T10:23:13+00:00Added an answer on May 26, 2026 at 10:23 am

    If I understand what you are asking, rather than attempting to append onto the array with .=, you should be using the [] notation to append to the array:

    //Initialize reunits as an array
    $reunits = array();
    
    
    foreach($query_r->result() as $idx=>$val){
        $hotel_id = $val->hotel_id;
        $query = $this->db->get_where('tour_foreign_units', array('hotel_id' => $hotel_id));
            $units_data = array();
            foreach ($query->result() as $index=>$row) {
                $units_data[] = array(
                    'name' => $row->name,
                    'price' => $row->price,
                    'extra' => $row->extra,
                    'hotel_id' => $row->hotel_id
                );
            }
    
    
        // Append the array $units_data onto $reunits
        // since $units_data is already an array
        $reunits[] = $units_data;
    }
    
    // Now the JSON output should look like you expect
    echo json_encode($reunits);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was following the tutorial here: http://net.tutsplus.com/tutorials/php/how-to-authenticate-your-users-with-facebook-connect/ But I can't get past the first
I am using following PHP code for trigger creation but always get error, please
I'm working with PHP 5 here. I have the following code: $data = json_decode($_POST['data']);
Hello I have the following php code here: $username = trim(mysql_real_escape_string($username)); $password = md5(trim(mysql_real_escape_string($password)));
i have the following search form <?php echo $this->Form->create('Order', array('action' => 'search','type'=>'get'));?> <?php echo
I have the following code: <?php include('settings.php'); //Here I have my connection string $result
The following PHP code snippet uses GD to resize a browser-uploaded PNG to 128x128.
I am running following PHP code to interact with a MS Access database. $odbc_con
I am using following PHP code to connect to MS Access database: $odb_conn =
I have the following php code, which has been snipped for brevity. I am

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.