I'm developing the script, do a search in an array with one or several keywords, which is the following script:
$url= "http://ift.tt/1JqYyQ7".date('d')."&output=json&groupby=country-adspace&period_group_by=day";
function search($array, $key, $value)
{
$results = array();
if (is_array($array)) {
if (isset($array[$key]) && $array[$key] == $value) {
$results[] = $array;
}
foreach ($array as $subarray) {
$results = array_merge($results, search($subarray, $key, $value));
}
}
return $results;
}
$json = file_get_contents($url);
$arr = json_decode($json, TRUE);
$my_date_arr = search($arr, 'ADSPACE', '41432');
I then returned the key, containing only that number as keyword. and I do another foreach to show only keys containing the characters.
<?php
foreach ($my_date_arr as $key=>$value) :
$country = $value['COUNTRY'];
$clicks = $value['CLICKS'];
$fecha = $value['DATE'];
$adspace = $value['ADSPACE'];
?>
<td><?= $country; ?></td>
<td><?= $clicks; ?></td>
<td><?=$fecha;?><td>
<td><?=$adspace;?><td>
</tr>
<?php endforeach;?>
it all works perfectly, the problem is I want to make two requests to the same function with a different value for example:
$my_date_arr = search($arr, 'ADSPACE', '41432');
$my_date_arr = search($arr, 'ADSPACE', '41755');
the goal is to look into an array a predetermined value, then return the key that contains the value and thus only make a foreach of what I find in the foreach, but also need is to make several requests in that foreach to I return the entire result in a single request.
Aucun commentaire:
Enregistrer un commentaire