简体   繁体   English

我试图在REST API的数组中返回一些结果我只能返回单个值,因为值在PHP中被覆盖

[英]I am trying to return some results in an array for rest api I am only able to return a single value as values are being overide in php

function get_all_activity_by_category(){

    $id = $this->input->get('id');

    $data['activity_category'] = $this->users_model->single_activity_category($id);

    $activity_category = $data['activity_category'];

    $data['activities_by_category'] = $this->users_model->list_of_activities($id);

    $activities_by_category = $data['activities_by_category'];

    foreach($activities_by_category as $activity)

        $activity_id = $activity->activity_id;



    $data['activity_session'] =  $this->users_model->search_sessions_by_activity($activity_id);


    $activity_session = $data['activity_session'];



    header('Access-Control-Allow-Origin: *');
    header('Content-Type: application/json');



     return $this->output
    ->set_content_type('application/json')
    ->set_status_header(200)
    ->set_output(json_encode(array('activity_category'=>$activity_category,'activity'=>$activities_by_category,'activity_session'=>$activity_session),JSON_UNESCAPED_SLASHES));


  }

I want results in array for session and venues but I am getting empty array, I have implemented the code for sessions and venues but it didn't work. 我希望将结果放在会议和场所的数组中,但是我得到的是空数组,我已经实现了会议和场所的代码,但没有用。

在此处输入图片说明

Assuming that there is data to be stored and that you want $activity_session to be a list of the sessions, your foreach loop was just looping over the id's and leaving $activity_id with the last value. 假设有要存储的数据,并且您希望$activity_session是会话列表,那么您的foreach循环只是遍历id并将$activity_id保留$activity_id最后一个值。 You should use this to build up a list of sessions... 您应该使用它来建立会话列表...

    $activity_session = array();
    foreach($activities_by_category as $activity)  {
        $activity_session[] =  $this->users_model->search_sessions_by_activity($activity->activity_id);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎么能在PHP中返回值(html表) - How am I able to return value in PHP (html table) PHP返回值……我缺少什么? - PHP return value… what am I missing? 我无法使用json对象获取返回值 - I am not able to get the return value on using json object 使用PHP中的表格,我试图返回取决于输入的SQL值的SQL值? - Using a form in PHP, I am trying to return an SQL value dependant on an entered SQL value? 当我尝试获取用户ID时,它返回null值 - It return null value when i am trying to get user id 我无法创建数组中的PHP数组 - Php array with in array i am not able to create 我正在尝试将数组值绑定到 php pdo 中的一个准备好的语句,但只有绑定的数组的第一个元素 - i am trying to bind array value a prepared statement in php pdo but only the first element of the array that is bind 我试图返回一个用户对象数组,但我的变量 $database->FetchArray() 返回 false - I am trying to return an array of User objects but my variable $database->FetchArray() return false 我正在尝试仅使用PHP制作幻灯片 - I am trying to make an slideshow only with PHP 我不知道为什么这些不打印?...我是学习 PHP 的新手...我正在尝试输入 2 个数字并返回两者中较大的一个 - I don't know why these are not printing?... I am new to learning PHP... I am trying to input 2 numbers and return the larger of the two
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM