tengo lo siguiente
Código PHP:
<?PHP
$data = '{
"result": {
"trabajo": true,
"datos": [
{
"id": "4000",
"date": "6/18/2012",
"idunico": "57954022"
},
{
"id": "4001",
"date": "5/11/2011",
"idunico": "57939700"
},
{
"id": "4002",
"date": "6/18/2012",
"idunico": "58516719"
},
{
"id": "4003",
"date": "6/12/2012",
"idunico": "165498461"
},
{
"id": "4004",
"date": "5/11/2011",
"idunico": "123456789"
}
]
}
}';
$tem = 4004;
for ($i=4000; $i < $tem ; $i++) {
function find($v){
global $buscar,$res,$i;
if( $v['id'] == $i ){
$res = $v['idunico'];
//return true;
} else {
return false;
}
}
$data = json_decode($data, true);
$datos = $data['result']['datos'];
array_filter($datos, "find");
echo $res;
}
?>
de esta manera funciona fsin el for
Código PHP:
<?PHP
$buscar = "4003";
$data = '{
"result": {
"trabajo": true,
"datos": [
{
"id": "4000",
"date": "6/18/2012",
"idunico": "57954022"
},
{
"id": "4001",
"date": "5/11/2011",
"idunico": "57939700"
},
{
"id": "4002",
"date": "6/18/2012",
"idunico": "58516719"
},
{
"id": "4003",
"date": "6/12/2012",
"idunico": "165498461"
},
{
"id": "4004",
"date": "5/11/2011",
"idunico": "123456789"
}
]
}
}';
//$tem = 4004;
//for ($i=4000; $i < $tem ; $i++) {
function find($v){
global $buscar,$res,$i;
if( $v['id'] == $buscar){
$res = $v['idunico'];
//return true;
} else {
return false;
}
}
$data = json_decode($data, true);
$datos = $data['result']['datos'];
array_filter($datos, "find");
echo $res;
//}
?>
Espero alguien me pueda audar gracias de antemano