I am using php curl to connect to my API, i want only retrieve the "item_name" and "item_id" and allow to choose what they want from the retrieved data via check box.
How can I make a check box for every "item_name" from the JSON or JSON_DECODE data.
I have tried many array search and key_exist function however was still unable to succeed, I need to store all item_id and item_name perhaps in a separate array for further use
$data = array(
"query" => "Cookies `n Cream?",
"appId" => "",
"appKey"=> ""
);
$data_string = json_encode($data);
$url_1='http://ift.tt/1KlYKM7';
function sendfunc($url, $post){
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
$result = curl_exec($ch);
curl_close($ch);
global $result_arr;
$result_arr = (array) json_decode($result, true);
/* print_r($result_arr); */
}
/* " " . sendfunc($url_1, $data_string); */
echo '<form method="post">';
echo 'foreach {
<input id="'.$item_arr.'" value="'.$result_arr.'" name="$item_arr" type="checkbox" >';
?>
}
<input type="submit">
</form>
From what I understand is before and after execution the json is stored in an php array however I don't understand why print_r($result_arr) is not working , and that I cannot access $result_arr outside the function hence I made it global even though its bad practice
please illustrate your explanation or suggestions by examples
Aucun commentaire:
Enregistrer un commentaire