Ehsan Ehsan - 1 year ago 90
PHP Question

PHP - storing array in one variable

i want to store

for using at
$content_lnk = array('chat_id' => $chatid,'text' => "$message_lnk" );

but my snippet not work. help me please !

foreach ($result as $user) {
$user = $user['movie_lnk'];
$message_lnk = print_r($user, true);
$content_lnk = array('chat_id' => $chatid,'text' => "$message_lnk" );

Answer Source

you're not building an array with this code, you're just setting $user to the last value within $result

You should have another variable, $links and do the following within the for loop.


And then on line 3, if you want to store the array as a string use:

$message_lnk=implode(", ", $links);

Or as an array:

$message_lnk=$links; $content_lnk=array('chat_id'=>$chat_id, 'text'=>$message_lnk)

Notice I removed the quotation marks around $message_lnk

Hope that helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download