I am trying to perform a GET request. The data is in the format as follows:
key=STRING (5 letters upper and lowercase)
num=INTEGER (2 digit number from 1-99)
{"data":"key=XXXXX, num=xx, key=XXXXX, num=xx"}
This is what I have so far:
<?php
$ch = curl_init('link_here');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
?>
Not sure how to sort the data and output values over 10 only.
Thanks
your question is not clear We need more information,
but if you have a long string like this
{"data":"key=str50, num=50, key=str01, num=1, key=str15, num=15, key=str08, num=8, key=str99, num=99"}
just decode Json and explode your array like this
$json = '{"data":"key=str50, num=50, key=str01, num=1, key=str15, num=15, key=str08, num=8, key=str99, num=99"}';
$encode = json_decode($json);
$data = $encode->data;
$explode = explode(",",$data);
$array = array();
for($i=0;$i<sizeof($explode);$i++){
if($i!=0)$i++;
$key = explode("=",$explode[$i]);
$val_next = explode("=",$explode[$i+1]);
if($val_next[1]>10)
$array[$key[1]] = $val_next[1];
}
asort($array);
print_r($array);
output is
Array ( [str15] => 15 [str50] => 50 [str99] => 99 )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.