我正在编写自己的php类,该类中有多个函数。类似这样:
class JSON_API_Hello_Controller {
public function test_cat(){
global $json_api;
$posts = $json_api->introspector->get_posts(array( \'cat\' => 3));
return $this->posts_object_result_bycat($posts);
}
public function test_cat1() {
global $json_api;
$posts = $json_api->introspector->get_posts(array( \'cat\' => 2));
return $this->posts_object_result_bycat($posts);
}
protected function posts_object_result_bycat($posts) {
global $wp_query;
return array(
\'count\' => count($posts),
\'pages\' => (int) $wp_query->max_num_pages,
\'posts\' => $posts
);
}
public function mix_cat(){
$first_cat = $this->test_cat();
$second_cat = $this->test_cat1();
$json1 = json_decode($first_cat , true);
$json2 = json_decode($second_cat, true);
$final_array = array_merge($json1, $json2);
// Finally encode the result back to JSON.
$final_json = json_encode($final_array);
}
}
我试过这样的东西。我想打电话给test_cat()
和test_cat1()
其他函数中的函数,如mix_cat()
在同一个类中。两种功能(test_cat()
&;test_cat1()
) 返回json对象。两个返回的json对象都将加入mix_cat()
作用请建议我如何拨打testcat()
&;test_cat1()
中的函数mix_cat()
并将这两个函数的结果mix_cat()
作用