0

こんにちは私はPHPを初めて使用しますが、ツイート配列を返すために配列にデータを入力する方法を知りたいです。

<?php

class TwitterService {
private $params = null;
private $tweets = array(

);

public function getParams() {
    return $this->params;
}

public function setParams($params) {
    $this->params = $params;
}


public function __construct($params) {
    $this->setParams($params);
}
public function getTweets(){
    private $tweet1 = new Tweet(
            id = 253338336415064064,
            created_at = 'Wed, 03 Oct 2012 03:39:00 +0000',
            profile_image_url = 'http:\/\/a0.twimg.com\/profile_images\/1529778154\/Facebook_normal.jpg',
            text = 'Lo real es lo real by @AnaliaRob tratando de expresarse vaya 1 a saber sobre q! Es un proverbio milenario. Only xa genios'
        );
    private $tweet2 = new Tweet(
            id: 253324444091703298,
            created_at: 'Wed, 03 Oct 2012 02:43:48 +0000',
            profile_image_url: 'http:\/\/a0.twimg.com\/profile_images\/1529778154\/Facebook_normal.jpg',
            text: 'Lo real es lo real by @AnaliaRob, trantando de expresarse vaya uno a saber sobre que!'
        );  

    return $tweets;
}

class Tweet{
    private $id = null;
    private $created_at = null;
    private $profile_image_url = null;
    private $text= null;
};

どうもありがとうございます。

4

3 に答える 3

1
$tweets[] = $myTweet;

また

$tweets = array( $tweet1, $tweet2 );

編集:

public function getTweets(){
    private $tweet1 = new Tweet(
            id = 253338336415064064,
            created_at = 'Wed, 03 Oct 2012 03:39:00 +0000',
            profile_image_url = 'http:\/\/a0.twimg.com\/profile_images\/1529778154\/Facebook_normal.jpg',
            text = 'Lo real es lo real by @AnaliaRob tratando de expresarse vaya 1 a saber sobre q! Es un proverbio milenario. Only xa genios'
        );
    private $tweet2 = new Tweet(
            id: 253324444091703298,
            created_at: 'Wed, 03 Oct 2012 02:43:48 +0000',
            profile_image_url: 'http:\/\/a0.twimg.com\/profile_images\/1529778154\/Facebook_normal.jpg',
            text: 'Lo real es lo real by @AnaliaRob, trantando de expresarse vaya uno a saber sobre que!'
        );  
    // Option 1
    return array( $tweet1, $tweet2 );

    // Option 2
    $result = array();
    $result[] = $tweet1;
    $result[] = $tweet2;
    return $result;
}
于 2012-10-05T14:02:07.620 に答える
1
$tweets = array( $tweet1, $tweet2 );
return $tweets;

編集 :

$tweets説明すると、宣言ゾーンにarray()を設定することはできません。これは、まだ存在していないため、関数で宣言/割り当てを行うため$tweet1です。$tweet2getTweets()

コード内の他の場所にアクセスする必要がない場合は、@MarvinLabsで示されているように宣言を$tweetsスキップして入力できます。$tweetsreturn array( $tweet1, $tweet2 );getTweets()

于 2012-10-05T14:13:18.720 に答える
0

関数内で、この方法でそれらにアクセスできますgetTweets

  $tweets = array( $tweet1, $tweet2,...);
于 2012-10-05T14:11:36.123 に答える