How to check the array keys in php to store array values in mysql. I am trying to store the "id" if the array have ("message") AND ("message" AND "story") key.
Array
array (
0 =>
array (
'message' => 'Insane!!!!!',
'story' => 'Ankan shared TIMES NOW\'s video.',
'created_time' =>
array (
'date' => '2016-02-16 17:15:49.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
),
'id' => '10154521329397892_10154555849367892',
),
1 =>
array (
'story' => 'Ankan shared Filmydrama\'s video.',
'created_time' =>
array (
'date' => '2016-02-12 14:05:15.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
),
'id' => '10154521329397892_10154545385862892',
),
2 =>
array (
'story' => 'Ankan shared Kya Yehi Hain Acche Din?\'s video.',
'created_time' =>
array (
'date' => '2016-02-12 03:34:32.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
),
'id' => '10154521329397892_10154544563382892',
),
3 =>
array (
'story' => 'Ankan shared a link.',
'created_time' =>
array (
'date' => '2016-02-12 03:28:09.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
),
'id' => '10154521329397892_10154544555572892',
),
4 =>
array (
'message' => 'R.I.P Jaihind',
'story' => 'Ankan shared The Hindu\'s post.',
'created_time' =>
array (
'date' => '2016-02-11 07:46:59.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
),
'id' => '10154521329397892_10154542597202892',
),
5 =>
array (
'story' => 'Ankan posted from Change.org.',
'created_time' =>
array (
'date' => '2016-02-11 05:09:08.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
),
'id' => '10154521329397892_10154542373792892',
),
6 =>
array (
'message' => 'Johnson & Johnson Finally Admits: Their Baby Products Contain Cancer-Causing Chemicals | ',
'created_time' =>
array (
'date' => '2016-02-11 01:38:33.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
),
'id' => '10154521329397892_10154542027992892',
),
7 =>
array (
'story' => 'Ankan shared a link.',
'created_time' =>
array (
'date' => '2016-02-09 17:16:07.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
),
'id' => '10154521329397892_10154538723082892',
),
I tried with the following code, but it is not giving anything.
$total_posts = array();
$posts_response = $posts_request->getGraphEdge();
if($fb->next($posts_response)) {
$response_array = $posts_response->asArray();
$total_posts = array_merge($total_posts, $response_array);
while ($posts_response = $fb->next($posts_response)) {
$response_array = $posts_response->asArray();
$total_posts = array_merge($total_posts, $response_array);
}
$array = json_encode($total_posts, true);
} else {
$posts_response = $posts_request->getGraphEdge()->asArray();
print_r($posts_response);
}
$my_arr = json_decode($array, true);
ob_start();
$data = var_export($my_arr);
ob_end_clean();
/*$story = $data;
foreach( $my_arr as $row )
$story .= " $row[message]\n";
$message_id = $data;
foreach( $my_arr as $row )
$message_id .= " $row[id]\n";*/
$total_posts[0] = array('message', 'story', 'created_time', array('date', 'timezone_type', 'timezone'),'id');
foreach ($total_posts as $row) {
if (isset($row['story']) {
if (isset($row['message']) {
$message_id .= "$row[id]\n";
$story .= " $row[message]\n";
} else {
// only story
}
} else {
$message_id .= "$row[id]\n";
$story .= " $row[message]\n";
}
}
I would like to get the output like
-----------------------------------------------------------------
id | Messages
-----------------------------------------------------------------
10154521329397892_10154555849367892 | Insane!!!!!
10154521329397892_10154542597202892 || R.I.P Jaihind
-----------------------------------------------------------------
The above id will be associated with the message if and only if "message" key exists in the array.
$row['id']to$message_id, i.e. finally you have a string likeid\n10154521329397892_10154545385862892\n10154521329397892_10154544563382892\n...etc. Does your code print any messages?$total_posts[0]due$total_posts[0] = array('message', 'story', 'created_time', array('date', 'timezone_type', 'timezone'),'id');. Can you update your question, I don't figure out what you need to see finally. What kind of record you want to save into database?