Arrays in a single index

0

I've done this question today , helped me a lot, now I have the code:

foreach ($tokens as $row) {
    $token1[] = $row['oauth_token'];
    $token2[] = $row['oauth_token_secret'];
}

var_dump($token1);
var_dump($token2);

And it returns me:

Iwantedtoturnthesetokensallinto1indexjusthowcanIdothis?

Example:

0=>string'todosaqui';

===============================================

EDIT:1

Iwanttoextractindexes,fromarraysforexample,Inowhavethis:

usingthiscode:

while($tokens=$this->selectTokens()){foreach($tokensas$row){$tokenList[]=['oauth_token'=>$row['oauth_token'],'oauth_token_secret'=>$row['oauth_token_secret'],];}#$connection=newTwitterOAuth(CONSUMER_KEY,CONSUMER_SECRET,$tokenList['oauth_token'],$tokenList['oauth_token_secret']);var_dump($tokenList);break;}

Well,Ithinkyou'vefigureditout,nowIwantyoutounderstandthis:

$connection=newTwitterOAuth(CONSUMER_KEY,CONSUMER_SECRET,$tokenList['oauth_token'],$tokenList['oauth_token_secret']);

Thatis,getalloauth_tokenandoauth_token_secret,whichcomesfromabancodedados,todoalooping.ButdoingsoIgetthis:

Just here $tokenList['oauth_token'], $tokenList['oauth_token_secret']

    
asked by anonymous 25.07.2017 / 23:43

1 answer

2

By adjusting the code that has now shown connection the connection must pass into for :

while ($tokens = $this->selectTokens()) {
    foreach ($tokens as $row) {
        $tokenList[] = [
            'oauth_token'               => $row['oauth_token'],
            'oauth_token_secret'    => $row['oauth_token_secret'],
        ];

        //uma conexao para cada registo aqui
        $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $tokenList['oauth_token'], $tokenList['oauth_token_secret']);
    }
}

//agora aqui tem uma lista de conexões estabelecidas em $connection

print_r($connection);

Simpler is to use $row directly:

while ($tokens = $this->selectTokens()) {
    foreach ($tokens as $row) {  
        $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, 
                                         $row['oauth_token'], $row['oauth_token_secret']);
    }
}
    
26.07.2017 / 00:42