Can1 Can1 - 5 months ago 12
HTML Question

Php code inside array

How can i add the "for" function output inside the array? Thanks

for($idid = 0; $idid <= $say; $idid++) {
echo "@";
print_r($string[$idid]['screen_name']);
echo " ";
}

$url = "https://api.twitter.com/1.1/statuses/update.json";
$twitter = new TwitterAPIExchange($settings);
$requestMethod = 'POST';
$response = $twitter->setPostfields(
array(
'status' => "I NEED TO ADD FOR FUNCTION OUTPUT HERE")
)
->buildOauth($url, $requestMethod)
->performRequest();

Answer

You should save to a variable instead of printing to screen like this:

$status = "";
for($idid = 0; $idid <= $say; $idid++) {
    $status .= "@";
    $status .= print_r($string[$idid]['screen_name'], true);
    $status .= " ";
}

The second parameter from print_r is to return the output instead for printing it. You can check more here

And after that use the $status variable in your array like this:

$response = $twitter->setPostfields(
    array('status' => $status)
)