The contents of my array, after applying JSON decode to the post data, look like this:
Array
(
[0] => Array
(
[meeting_name] => myMeeting1
[ip] => 00.00.00.00
[response] => 250 message accepted for delivery
[event] => delivered
[email] => myemail@something.com
[timestamp] => 1485811028
[uID] => 01130
)
[1] => Array
(
[meeting_name] => myMeeting1
[event] => processed
[email] => myemail@something.com
[timestamp] => 1485811026
[uID] => 01130
)
)
I want to be able to create variables and assign them the values for each of the keys within the array (doing this in order to be able to store only some values in a DB).
For example: $meetingName = $post_data['meeting_name'];
(I tried doing this, but do not get any value in return.
I have also tried looking for answers on different posts, such as: PHP - Accessing Multidimensional Array Values, which looks similar to my array; however, when applying that answer I get a PHP warning:
PHP Warning: Invalid argument supplied for foreach()...
Other StackOverflow I tried to work with, but did not help:
Any idea why I cannot access the values? Thank you in advance!
*Updated on 2/1/17 to reflect code
Here's the the code I have:
if(is_array($post_data) || $post_data instanceof Traversable){
foreach ($post_data as $event) {
$meeting_name = $event['meeting_name'];
$converted_date = date("Y-m-d H:i:s", $event['timestamp']);
echo "Meeting name: " . $meeting_name . "<br>";
echo "Date: " .$converted_date;
}
}
*Update on 2/3/17 The code above works. I am using it to manipulate variables and create statements based on what you want store in a database.
The article below helps too:
I hope this helps someone!