I have an array like this:
Array ( [10209064245580796] => Array ( [0] => Array ( [hashed_token] => ) [1] => Array ( [password] => ) [2] => Array ( [email] => klemen.pevc@gmail.com ) ) [10207252567926988] => Array ( [0] => Array ( [hashed_token] => ) [1] => Array ( [password] => 716b64c0f6bad9ac405aab3f00958dd1 ) [2] => Array ( [email] => milvuk@gmail.com ) ) )
That I made this way:
$users
looks like this:
Array ( [0] => 10209064245580796 [1] => 10207252567926988)
$arrayOfFields
looks like this:
Array ( [0] => hashed_token [1] => password [2] => email )
So:
$array=array();
foreach($users as $user){
$array[$user]=array();
foreach($arrayOfFields as $getFieldValue) {
$user = '' . $user . '';
$query = "SELECT `$getFieldValue` FROM $table WHERE `$column`= $user";
$result = $mysqli->query($query);
$fetchResult = $result->fetch_assoc();
$getFieldValue = '' . $getFieldValue . '';
$finalValue = $fetchResult[$getFieldValue];
array_push($array[$user] ,array($getFieldValue=>$finalValue));
}
}
And after this two foreachs
I get an array $array
as shown above in first example that I'm sending via cURL
with this code:
$data = array('facebook_app_id' => $facebook_app_id, 'facebook_ids' => $facebook_ids,'values_for_custom_fields' => $array);
$endpoint_url = 'https://servis-racunara.net/api/index.php';
$curl = curl_init($endpoint_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Authorization: Token ".$token));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$curl_response = curl_exec($curl);
curl_close($curl);
//you do not need to print results, this is just for debugging purposes
$result = $curl_response;
print_r($result);
So inside script of this endpoint https://servis-racunara.net/api/index.php (on which I'm sending some data, including $array
) when i do print_r($_POST)
I get an array like this:
Array ( [facebook_app_id] => 1512823699024883 [facebook_ids] => 10209064245580796,10207252567926988[values_for_custom_fields] => Array )
So, under key values_for_custom_fields
is stored $array
array that I need to process. When I do print_r($_POST['values_for_custom_fields']);
it just says 'Array', and when I try this:
foreach($_POST['values_for_custom_fields'] as $anything) {
echo($anything);//same with print_r
}
Server says :
Warning: Invalid argument supplied for foreach()
Any ideas?