Array values manipulation

Hello,

I have a sort of array printed from a JSON object (see at the end) and i would like my script to parse the values in [text], [sender_screen_name], [id] and [sender_id] from it. I want my program to automatically use the values from [text] and insert them into another array which then posts these values to feed a server side script for a chatbot and [sender_screen_name] and [sender_id] to be used for teh method that posts the answer to twitter.



$direct_message = $OAuth->get('https://api.twitter.com/1/direct_messages.json?count=1&page='); // pulls a direct message from my automated Twitter account, one at the time

echo "<pre>"; //

print_r ($direct_message); // this to visualise the array in a readable format

echo "</pre>";  // ditto

$data = array ("say"=>"the value of [text] from the array i got from twitter should be parsed here  ", "bot_id"=>"1", "format"=>"xml"); // these are the values to be posted to the
                                                                                                                                                                                          page to feed the chatbot
$url = "http://localhost/program-o/gui/xml/index.php";

$fields = '';
foreach($data as $key => $value) {
  $fields .= $key . '=' . $value . '&';
}
rtrim($fields, '&');

   $post = curl_init();

   curl_setopt($post, CURLOPT_URL, $url);
   curl_setopt($post, CURLOPT_POST, count($data));
   curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
   curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);

   $result = curl_exec($post);

   curl_close($post);


$dm->post('direct_messages/new', array('text' =>answer from bot, 'screen_name' =>the value i am trying to get from the array i got from twitter, 'sender_id'=>wanna do the same as screen name)); // this is the method to post the answer from the chatbot back to twitter.



Here’s the array that has the data from Twitter:

Array
(
[0] => stdClass Object
(
[sender_screen_name] => chanianaus
[sender] => stdClass Object
(
[id] => 31084145
[id_str] => 31084145
[default_profile] => 1
[profile_use_background_image] => 1
[location] => Dublin
[profile_text_color] => 333333
[statuses_count] => 1
[following] => 1
[utc_offset] =>
[profile_sidebar_border_color] => C0DEED
[listed_count] => 0
[name] => Swaran Singh
[protected] =>
[profile_background_tile] =>
[is_translator] =>
[profile_sidebar_fill_color] => DDEEF6
[contributors_enabled] =>
[profile_image_url_https] => https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png
[geo_enabled] =>
[friends_count] => 12
[description] =>
[profile_background_image_url_https] => https://si0.twimg.com/images/themes/theme1/bg.png
[default_profile_image] => 1
[notifications] =>
[profile_image_url] => http://a0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png
[show_all_inline_media] =>
[favourites_count] => 0
[followers_count] => 9
[follow_request_sent] =>
[profile_background_color] => C0DEED
=>
[screen_name] => chanianaus
[verified] =>
[lang] => en
[created_at] => Tue Apr 14 08:22:02 +0000 2009
[profile_background_image_url] => http://a0.twimg.com/images/themes/theme1/bg.png
[profile_link_color] => 0084B4
[time_zone] =>
)

        [id_str] =&gt; 200588152493191170
        [created_at] =&gt; Thu May 10 14:08:36 +0000 2012
        [recipient_screen_name] =&gt; Infobot2012
        [recipient_id] =&gt; 428575951
        [sender_id] =&gt; 31084145
        [recipient] =&gt; stdClass Object
            (
                [id] =&gt; 428575951
                [id_str] =&gt; 428575951
                [default_profile] =&gt; 1
                [profile_use_background_image] =&gt; 1
                [location] =&gt;
                [profile_text_color] =&gt; 333333
                [statuses_count] =&gt; 11
                [following] =&gt;
                [utc_offset] =&gt;
                [profile_sidebar_border_color] =&gt; C0DEED
                [listed_count] =&gt; 0
                [name] =&gt; Diego Canale
                [protected] =&gt;
                [profile_background_tile] =&gt;
                [is_translator] =&gt;
                [profile_sidebar_fill_color] =&gt; DDEEF6
                [contributors_enabled] =&gt;
                [profile_image_url_https] =&gt; https://si0.twimg.com/sticky/default_profile_images/default_profile_6_normal.png
                [geo_enabled] =&gt;
                [friends_count] =&gt; 18
                [description] =&gt;
                [profile_background_image_url_https] =&gt; https://si0.twimg.com/images/themes/theme1/bg.png
                [default_profile_image] =&gt; 1
                [notifications] =&gt;
                [profile_image_url] =&gt; http://a0.twimg.com/sticky/default_profile_images/default_profile_6_normal.png
                [show_all_inline_media] =&gt;
                [favourites_count] =&gt; 0
                [followers_count] =&gt; 3
                [follow_request_sent] =&gt;
                [profile_background_color] =&gt; C0DEED
                 =&gt;
                [screen_name] =&gt; Infobot2012
                [verified] =&gt;
                [lang] =&gt; en
                [created_at] =&gt; Sun Dec 04 22:56:38 +0000 2011
                [profile_background_image_url] =&gt; http://a0.twimg.com/images/themes/theme1/bg.png
                [profile_link_color] =&gt; 0084B4
                [time_zone] =&gt;
            )

        [id] =&gt; 2.0058815249319E+17
        [text] =&gt; test
    )

)

So your references are that FOREACH items as $item in your base array, you want to put into an ARRAY $item->text, $item->sender_screen_name, $item->id, $item->recipient_id.