我有这个阵列。我尝试了一些东西,但没有得到我想要的。我尝试了一个foreach循环,但是它看起来并不容易,这个过程需要很长的时间。
stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[display_number] => 100140
[client] => stdClass Object
(
[name] => TAUQIR SHEIKH ET AL
)
)
[1] => stdClass Object
(
[display_number] => 100141
[client] => stdClass Object
(
[name] => YOLANDA SHEIKH ET AL
)
)我希望它是一个简单的数组
[0] => Array
(
[0] => 100140
[1] => TAUQIR SHEIKH ET AL
)
[1] => Array
(
[0] => 100141
[1] => YOLANDA SHEIKH ET AL
)好的,旧代码起作用了,但是现在他们更新了API,这使它变得更糟了。现在的反应是
(
[data] => Array
(
[0] => stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[display_number] => 100140
[client] => stdClass Object
(
[name] => TAUQIR SHEIKH ET AL
)
)
[1] => stdClass Object
(
[display_number] => 100141
[client] => stdClass Object
(
[name] => YOLANDA SHEIKH ET AL
)
)我用新密码试过这个..。但是数组是空的。我哪里出问题了?
//clean and make into an array
$matter_array = array();
if(!empty($response_Decode->data->data) &&
is_array($response_Decode->data->data)) {
foreach ($response_Decode->data->data as $info) {
$d = array();
$d[] = $info->display_number;
$d[] = $info->client->name;
$matter_array[] = $d;
}
}
print_r($matter_array); //For testing
die(); //For testing发布于 2017-11-16 18:01:54
好的,我只是简化了数组..。这很管用!
//clean and make into an array
$response_Decode=$response_Decode->data;
$response_Decode=$response_Decode[0];
//print_r ($response_Decode);
//die(); //For testing
$matter_array = array();
if(!empty($response_Decode->data) && is_array($response_Decode->data)) {
foreach ($response_Decode->data as $info) {
$d = array();
$d[] = $info->display_number;
$d[] = $info->client->name;
$matter_array[] = $d;
}
}发布于 2017-10-25 22:53:01
我建议先询问是谁/什么进程填充数据集,并可能在那里进行调整。
如果不可用,则需要循环。
$results = array();
if(!empty($object->data) && is_array($object->data)) {
foreach ($object->data as $info) {
$d = array();
$d[] = $info->display_number;
if(!empty($object->client)) {
$d[] = $object->client->name;
}
$results[] = $d;
}
}
print_r($results);我对空()疑神疑鬼。代码没有经过测试,但应该会让您走上正确的轨道。
发布于 2017-10-26 17:58:07
所以你很亲密..。谢谢。
//clean and make into an array
$matter_array = array();
if(!empty($resp->data) && is_array($resp->data)) {
foreach ($resp->data as $info) {
$d = array();
$d[] = $info->display_number;
$d[] = $info->client->name;
$matter_array[] = $d;
}
}
print_r($matter_array)https://stackoverflow.com/questions/46942581
复制相似问题